google / GTMAppAuth

Apple platforms SDK for using AppAuth with Google libraries.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

get userinfo error "Insufficient Permission" after get authorization

zhouhuanjie opened this issue · comments

`GTMSessionFetcherService *fetcherService = [[GTMSessionFetcherService alloc] init];

fetcherService.authorizer =self.authorization;

// Creates a fetcher for the API call.
NSURL *userinfoEndpoint = [NSURL URLWithString:@"https://www.googleapis.com/oauth2/v3/userinfo"];
GTMSessionFetcher *fetcher = [fetcherService fetcherWithURL:userinfoEndpoint];
[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
    // Checks for an error.
    if (error) {
        // OIDOAuthTokenErrorDomain indicates an issue with the authorization.
        if ([error.domain isEqual:OIDOAuthTokenErrorDomain]) {
            [self setGtmAuthorization:nil];
            [self logMessage:@"Authorization error during token refresh, clearing state. %@", error];
            // Other errors are assumed transient.
        } else {
            [self logMessage:@"Transient error during token refresh. %@", error];
        }
        return;
    }

    // Parses the JSON response.
    NSError *jsonError = nil;
    id jsonDictionaryOrArray =
    [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
    
    // JSON error.
    if (jsonError) {
        [self logMessage:@"JSON decoding error %@", jsonError];
        return;
    }`

Printing description of jsonDictionaryOrArray:
{
"error_description" = "Insufficient Permission";
}

If you’re having an issue with the GTMAppAuth library, please let us know. But this sounds like a question about authorizing your client for the userinfo endpoint, which is not a GTMAppAuth question.