我在我的角度应用程序中使用angular-6-social-login进行Google登录。一切正常。但是我想在此指定托管域。因此,只有两个指定的域用户才能登录。当前,该模块不支持此功能。有什么办法可以覆盖它。
现有代码:
`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:false3. hosted_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的第二个选项提供您在配置选项中配置托管域。