sahat / satellizer

Token-based AngularJS Authentication
https://satellizer-sahat.rhcloud.com
MIT License
7.86k stars 1.13k forks source link

restrict google login with hd not working #1057

Open MikeWizzard opened 7 years ago

MikeWizzard commented 7 years ago

I need to restrict login with google to a specific domain but unfortunatly it still lets me login with any email this is the following code i have.

$authProvider.google({ hd: 'example.com', clientId: 'xxxxxxxxxxx.apps.googleusercontent.com', });

this.providers = { google: { name: 'google', url: '/auth/google', authorizationEndpoint: 'https://accounts.google.com/o/oauth2/auth', redirectUri: window.location.origin, requiredUrlParams: ['scope'], optionalUrlParams: ['display', 'hd'], scope: ['profile', 'email'], scopePrefix: 'openid', scopeDelimiter: ' ', display: 'popup', oauthType: '2.0', popupOptions: { width: 452, height: 633 }, state: function () { return encodeURIComponent(Math.random().toString(36).substr(2)); } } };

is there something wrong or missing? also i cannot see the email when logged in with google on the profile page. i only get image and display name.

Thanks in advance

houssem-yahiaoui commented 7 years ago

Hello, this might be a bit late but here you go for others reference, since you're adding "hd" optionalUrlParams, you will need simply to give it a value so my call if i was you will be the following:

$authProvider.google({
   hd: 'example.com',
   clientId: 'xxxxxxxxxxx.apps.googleusercontent.com',
});

this.providers = {
   google: {
     name: 'google',
     url: '/auth/google',
     authorizationEndpoint: 'https://accounts.google.com/o/oauth2/auth',
     redirectUri: window.location.origin,
     requiredUrlParams: ['scope'],
     optionalUrlParams: ['display', 'hd'],
     hd: "<your hd>"
     scope: ['profile', 'email'],
    scopePrefix: 'openid',
    scopeDelimiter: ' ',
    display: 'popup',
    oauthType: '2.0',
    popupOptions: { width: 452, height: 633 },
    state: function () { return encodeURIComponent(Math.random().toString(36).substr(2)); }
    }
};

Good luck, hope it helps.