-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FitBit: Authorization header required #200
Comments
So managed to get it working with a hack In NXOauth2Connection.m / - (NSURLConnection *)createConnection; I added in :
|
@chrisfoulds hey i had the same problem as you although your solution did not help me. do you think you could send your code |
That is it ! - all the code I had to add was those two lines. |
@chrisfoulds oh, i see.. I'm extremely new to github and oauth so any help would be very useful. I believe the error that I am still getting (the same one you got) has to do with the NXOAuth2Connect.m file. I may not have placed the code you used to hack it in the correct spot but its in the createConnetion method. All I can think of is that there is a bit of code in that method that has been deprecated to NSURLSession. I believe everything else I have is correct I just get the error 'Authorization header required' whenever I make a GET request. //This is the code in my AppDelegate.m file
//OAuth config
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[NXOAuth2AccountStore sharedStore] setClientID:@"XxXxXx"
secret:@"XxXxXxXxXx"
scope:[NSSet setWithObjects:@"activity", @"heartrate", @"location", @"nutrition", @"profile", @"settings", @"sleep", @"social", @"weight", nil]
authorizationURL:[NSURL URLWithString:@"https://www.fitbit.com/oauth2/authorize?response_type=token&client_id=227NJP&redirect_uri=myapp://handleOauthLogin&scope=activity%20heartrate%20location%20nutrition%20nutrition%20profile%20settings%20sleep%20social%20weight&expires_in=2592000"]
tokenURL:[NSURL URLWithString:@"https://api.fitbit.com/oauth2/access_token"]
redirectURL:[NSURL URLWithString:@"myapp://handleOauthLogin"]
keyChainGroup:@""
tokenType:@"Bearer"
forAccountType:@"fitbit"];
NSMutableDictionary *configuration = [NSMutableDictionary dictionaryWithDictionary:[[NXOAuth2AccountStore sharedStore] configurationForAccountType:@"fitbit"]];
NSDictionary *customHeaderFields = [NSDictionary dictionaryWithObject:@"application/x-www-form-urlencoded" forKey:@"Content-Type"];
[configuration setObject:customHeaderFields forKey:kNXOAuth2AccountStoreConfigurationCustomHeaderFields];
[[NXOAuth2AccountStore sharedStore] setConfiguration:configuration forAccountType:@"fitbit"];
[[NXOAuth2AccountStore sharedStore] requestAccessToAccountWithType:@"fitbit"];
return YES;
}
//Callback
- (BOOL) application:(UIApplication *)app openURL:(NSURL *)url options: (NSDictionary<NSString *, id> *)options
{
NSLog(@"We received a callback");
return [[NXOAuth2AccountStore sharedStore] handleRedirectURL:url];
}
|
@chrisfoulds also, not sure if this helps but if I move the two lines you provided in the 'NXOAuth2Connection.m' file up right before the NSURLConnection *aConnection bit I get the following error.. {"errors":[{"errorType":"invalid_client","message":"Invalid authorization header. Client id invalid. Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process."}],"success":false}oper/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/Accounts.framework/Accounts Like I said I'm not sure if I have your code in the correct location but I suppose that error shows that its a problem with the encoding for the clientID. I honestly have no clue what to do :( |
Your error is different to mine... however |
@chrisfoulds ok thank you very much I will look into using AFNetworking |
Hello, I had the same error. NSMutableDictionary *configuration = [NSMutableDictionary dictionaryWithDictionary:[[NXOAuth2AccountStore sharedStore] configurationForAccountType:@"fitbit"]]; NSString *authHeader = [NSString stringWithFormat:@"Basic %@", [[NSString stringWithFormat:@"%@:%@", kClientId, kClientSecretKey] base64EncodedString]]; [configuration setObject:@{@"Content-Type": @"application/x-www-form-urlencoded", @"Authorization": authHeader} forKey:kNXOAuth2AccountStoreConfigurationCustomHeaderFields]; [[NXOAuth2AccountStore sharedStore] setConfiguration:configuration forAccountType:@"fitbit"]; |
I am trying to connect to Fitbit in an iOS App
https://dev.fitbit.com/docs/oauth2/#authorization-page
I have put this code in the app startup
In my callback I do
and I invoke the auth using :
and I have the notification handlers that return as failure.
The app launches, safari, I login , say everything is ok, it then asks to return to my app.
I say ok, it returns but the notification from storing the token says
I just can not see what I have missed, any help appreciated.
The text was updated successfully, but these errors were encountered: