angular6 - 使用选定主机域的角度 gmail 登录
问题描述
我在我的 Angular 应用程序中使用 angular-6-social-login 进行谷歌登录。它工作正常。但我想在此指定托管域。所以只有两个指定的域用户能够登录它。目前此模块不支持此功能。有没有办法覆盖它。
现有代码:
`GoogleLoginProvider.prototype.initialize = function () {
var _this = this;
return new Promise(function (resolve, reject) {
_this.loadScript(_this.loginProviderObj, function () {
gapi.load('auth2', function () {
_this.auth2 = gapi.auth2.init({
client_id: _this.clientId,
scope: 'email'
});
_this.auth2.then(function () {
if (_this.auth2.isSignedIn.get()) {
resolve(_this.drawUser());
}
});
});
});
});
};`
我的要求:
`GoogleLoginProvider.prototype.initialize = function () {
var _this = this;
return new Promise(function (resolve, reject) {
_this.loadScript(_this.loginProviderObj, function () {
gapi.load('auth2', function () {
_this.auth2 = gapi.auth2.init({
client_id: _this.clientId,
scope: 'email',
hosted_domain:'abc.com'
});
_this.auth2.then(function () {
if (_this.auth2.isSignedIn.get()) {
resolve(_this.drawUser());
}
});
});
});
});
};`
解决方案
Angular 6 社交登录包不支持自定义配置来指定托管域。相反,您可以更改 node_modules 中的 angular-6-social-login.umd.js 文件。
更改 GoogleLoginProvider.prototype.initialize 函数并在 gapi.auth2.init 函数中添加以下详细信息
1. 范围应为“电子邮件” 2. fetch_basic_profile: false 3. hosts_domain: 您的域。
gapi.load('auth2', function () {
_this.auth2 = gapi.auth2.init({
client_id: _this.clientId,
scope: 'email',
fetch_basic_profile: false,
hosted_domain: <your-domain> ,
});
_this.auth2.then(function () {
if (_this.auth2.isSignedIn.get()) {
resolve(_this.drawUser());
}
});
});
这将适用于指定的域。
第二个选项您可以使用angularx-social-login为您提供在配置选项中配置托管域。
推荐阅读
- python - 使用用户输入的函数数据框名称字符串获取熊猫数据框
- javascript - 仅从嵌套数组中获取值
- css - 当元素在Angular中具有特定类时如何删除CSS类
- ios - 如何以编程方式将 UItextfield 占位符和文本更改为右对齐
- angular - Angular 8将字符串保存到本地文件
- node.js - 使用 GitLab CI 对 NodeJS 项目进行版本控制在验证条件部分不起作用
- string - 如何从 bash 中的字符串中删除最后一个点(句点)
- python - 当特定列的连续行值大于一个数字时,熊猫会删除行
- r - 在使用 for 循环在列表中定义的数据框中删除列
- docker - 更新 Discourse 后如何解决 502 Bad Gateway 问题?