ios - GTM OAuth2 unable to detect successful authentication -
i trying access user data fitbit using gtm oauth2. ios. gtmoauth2viewcontrollertouch working, , can log in no problem. after logged in, controller should able detect authentication stated:
the controller watch server redirect web view uri, uri not loaded, need not actual web page.
if use real url, load url straight forward. if use arbitrary url, won't @ all.
what right setting detect authentication?
- (gtmoauth2authentication *)authforfitbit { nsurl *tokenurl = [nsurl urlwithstring:@"https://api.fitbit.com/oauth2/token"]; // we'll make arbitrary redirecturi. controller watch // server redirect web view uri, uri not // loaded, need not 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; }
and following:
- (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 valid client id , client secret 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 authentication view sel sel = @selector(viewcontroller:finishedwithauth:error:); gtmoauth2viewcontrollertouch *viewcontroller; viewcontroller = [gtmoauth2viewcontrollertouch controllerwithauthentication:auth authorizationurl:authurl keychainitemname:keychainitemname delegate:self finishedselector:sel]; // push our sign-in view [[self navigationcontroller] pushviewcontroller:viewcontroller animated:yes]; }
Comments
Post a Comment