使用选定主机域的Gmail角登录

问题描述 投票:1回答:1

我在我的角度应用程序中使用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());
                    }
                });
            });
        });
    });
   };`
angular6 google-login
1个回答
0
投票

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的第二个选项提供您在配置选项中配置托管域。

© www.soinside.com 2019 - 2024. All rights reserved.