GTM OAuth2 не может обнаружить успешную аутентификацию

Я пытаюсь получить доступ к данным пользователя из Fitbit с помощью GTM OAuth2. Для iOS. GTMOAuth2ViewControllerTouch работает, и я могу войти без проблем. После того, как я вошел в систему, контроллер должен быть в состоянии обнаружить аутентификацию, как указано:

The controller will watch for the server to redirect the web view to this URI,
but this URI will not be loaded, so it need not be for any actual web page.

Если я использую реальный URL, он будет загружен прямо. Если я использую произвольный URL, он вообще ничего не сделает.

Какова правильная настройка для обнаружения аутентификации?

- (GTMOAuth2Authentication *)authForFitbit {
    NSURL *tokenURL = [NSURL URLWithString:@"https://api.fitbit.com/oauth2/token"];

    // We'll make up an arbitrary redirectURI.  The controller will watch for
    // the server to redirect the web view to this URI, but this URI will not be
    // loaded, so it need not be for any actual web page.
    NSString *redirectURI = @"http://www.notexistcallback.com";

    NSString *clientID = kFitbitClientID;
    NSString *clientSecret = kFitbitClientSecret;
    GTMOAuth2Authentication *auth;
    auth = [GTMOAuth2Authentication     authenticationWithServiceProvider:kFitbitServiceName
                                                         tokenURL:tokenURL
                                                      redirectURI:redirectURI
                                                         clientID:clientID
                                                     clientSecret:clientSecret];
    return auth;
}

И следующее:

- (void)signInToFitbit {
    [self signOut];

    GTMOAuth2Authentication *auth = [self authForFitbit];
    auth.scope = @"profile";

    if ([auth.clientID length] == 0 || [auth.clientSecret length] == 0) {
        NSString *msg = @"The sample code requires a valid client ID and client secret to sign in.";
        [self displayAlertWithMessage:msg];
        return;
    }

    NSString *keychainItemName = @"OAuth2 Sample: Fitbit";
    if ([self shouldSaveInKeychain]) {
    keychainItemName = kKeychainItemName;
    }

    NSURL *authURL = [NSURL URLWithString:@"https://www.fitbit.com/oauth2/authorize"];

    // Display the authentication view
    SEL sel = @selector(viewController:finishedWithAuth:error:);

    GTMOAuth2ViewControllerTouch *viewController;
    viewController = [GTMOAuth2ViewControllerTouch controllerWithAuthentication:auth
                                                           authorizationURL:authURL
                                                           keychainItemName:keychainItemName
                                                                   delegate:self
                                                           finishedSelector:sel];


    // Now push our sign-in view
    [[self navigationController] pushViewController:viewController animated:YES];
}

0 ответов

Другие вопросы по тегам