GTMAppAuth
GTMAppAuth copied to clipboard
User email is nil in OIDAuthState after authorization
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?
You need to add the scope OIDScopeEmail
to your scopes array to get the userEmail.
@WilliamDenniss should this get added to the migration section since gtm-oauth2 used to auto do this?
I have the same problem, I have already added OIDScopeEmail
to the scopes of the request, but userEmail remains nil
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.