GTMAppAuth icon indicating copy to clipboard operation
GTMAppAuth copied to clipboard

User email is nil in OIDAuthState after authorization

Open t0rn opened this issue 7 years ago • 4 comments

Here is code from your example

// builds authentication request
OIDAuthorizationRequest *request =
    [[OIDAuthorizationRequest alloc] initWithConfiguration:configuration
                                                  clientId:kClientID
                                              clientSecret:kClientSecret
                                                    scopes:@[OIDScopeOpenID, OIDScopeProfile]
                                               redirectURL:redirectURI
                                              responseType:OIDResponseTypeCode
                                      additionalParameters:nil];
// performs authentication request
self.appDelegate.currentAuthorizationFlow =
    [OIDAuthState authStateByPresentingAuthorizationRequest:request
        callback:^(OIDAuthState *_Nullable authState,
                   NSError *_Nullable error) {
  if (authState) {
    // Creates the GTMAppAuthFetcherAuthorization from the OIDAuthState.
    GTMAppAuthFetcherAuthorization *authorization =
        [[GTMAppAuthFetcherAuthorization alloc] initWithAuthState:authState];

    self.authorization = authorization;
    NSLog(@"Got authorization tokens. Access token: %@",
          authState.lastTokenResponse.accessToken);
  } else {
    NSLog(@"Authorization error: %@", [error localizedDescription]);
    self.authorization = nil;
  }
}];

Why GTMAppAuthFetcherAuthorization initialized by authState have nil userEmail? I used it and it was there. Even after using userInfo endpoint in your example there isn't user email. How can I get user email after authorization?

t0rn avatar Mar 20 '17 11:03 t0rn

You need to add the scope OIDScopeEmail to your scopes array to get the userEmail.

WilliamDenniss avatar Mar 21 '17 05:03 WilliamDenniss

@WilliamDenniss should this get added to the migration section since gtm-oauth2 used to auto do this?

thomasvl avatar Aug 01 '17 13:08 thomasvl

I have the same problem, I have already added OIDScopeEmail to the scopes of the request, but userEmail remains nil

Thomas-esimple avatar Jun 21 '18 16:06 Thomas-esimple

I have the same problem, I have already added OIDScopeEmail to the scopes of the request, but userEmail remains nil

After you add a new scope, make sure to do a fresh authorization instead of loading the serialized authorization object.

maxklint avatar Jan 12 '20 16:01 maxklint