Skip to content
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

How to Get Oauth token using Basic authorization #193

Open
alchemistgo87 opened this issue Aug 23, 2015 · 2 comments
Open

How to Get Oauth token using Basic authorization #193

alchemistgo87 opened this issue Aug 23, 2015 · 2 comments

Comments

@alchemistgo87
Copy link

I need to get Oauth token with basic authrization. Right now I have to manually add header with base 64 of server_clientid:server_secret as follows:

+ (void)initialize;

{
    NSSet *scpe=[[NSSet alloc]initWithObjects:@"read",@"write",nil];

    [[NXOAuth2AccountStore sharedStore] setClientID:@"my_server_client_id" secret:@"my_server_secret" scope:scpe authorizationURL:[NSURL URLWithString:@"http://192.168.1.14:8080/oauth/authenticate"] tokenURL:[NSURL URLWithString:@"http://192.168.1.14:8080/oauth/token"] redirectURL:nil keyChainGroup:nil tokenType:@"access_token" forAccountType:@"DNI"];

    NSMutableDictionary *configuration = [NSMutableDictionary dictionaryWithDictionary:[[NXOAuth2AccountStore sharedStore] configurationForAccountType:@"DNI"]];

    NSMutableDictionary *customHeaderFields = [NSMutableDictionary new ];

    [customHeaderFields setValue:@"application/x-www-form-urlencoded" forKey:@"Content-Type"];

    [customHeaderFields setValue:[NSString stringWithFormat:@"Basic %@",[MVHelpers getBase64FromClient:@"my_server_client_id" andSecret:@"my_server_secret"]] forKey:@"Authorization"];

//dictionaryWithObject:@"application/x-www-form-urlencoded" forKey:@"Content-Type"];



    [configuration setObject:customHeaderFields.mutableCopy forKey:kNXOAuth2AccountStoreConfigurationCustomHeaderFields];

    [[NXOAuth2AccountStore sharedStore] setConfiguration:configuration forAccountType:@"DNI"];


}

Is there some proper way to do this?

Also everything works fine(access_token and refresh_tokens are retrieved) with the above, but there is an issue. When the access_token expires, we get a crash as provided in the screen:

screen1
screen2

@toto
Copy link
Contributor

toto commented Aug 23, 2015

This does not seem like correct OAuth2 instead the key/secret are used as username/password in a basic auth. This is not supported since it's not OAuth2.

@alchemistgo87
Copy link
Author

In oauth2, to retrieve the access_token from server don't we have to use Basic authorization first. After that bearer token is send for each api. What else would you do to login a user?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants