GTM OAuth for IOS not working with Grails OAuth 2 provider -


i working on ios app , want use oauth authenticate app grails system have in place. grails system has oauth2 provider setup using plugin @ link below:

https://github.com/adaptivecomputing/grails-spring-security-oauth2-provider 

the oauth provider setup , work have tested url's shown below , authorisation code expected once access has been granted:

http://localhost:8080/app/oauth/authorize?response_type=code&client_id=clientid&redirect_uri=http://localhost:8080/app/ 

the issue having when use gtm oauth plugin ios google have set follows:

static nsstring *const kmyclientid = @"1"; static nsstring *const kmyclientsecret = @"secret"; static nsstring *const kkeychainitemname = @"systemkeychain";  - (gtmoauth2authentication *)systemauth {      // set token url system token endpoint.     nsurl *tokenurl = [nsurl urlwithstring:@"http://www.systemurl.co.uk/oauth/token"];      // set bogus redirect uri. won't used redirect     // intercepted oauth library , handled in app.     nsstring *redirecturi = @"http://www.systemurl.co.uk/";      gtmoauth2authentication *auth;     auth = [gtmoauth2authentication authenticationwithserviceprovider:@"system api"                                                              tokenurl:tokenurl                                                           redirecturi:redirecturi                                                              clientid:kmyclientid                                                          clientsecret:kmyclientsecret];      return auth; }  - (void)authorize:(nsstring *)service {     gtmoauth2authentication *auth = [self systemauth];      // prepare authorization url. pass in name of service     // wish authorize with.     nsurl *authurl = [nsurl urlwithstring:[nsstring stringwithformat:@"http://www.systemurl.co.uk/oauth/authorize"]];      // display authentication view     gtmoauth2viewcontrollertouch *viewcontroller;     viewcontroller = [ [gtmoauth2viewcontrollertouch alloc] initwithauthentication:auth                                                                   authorizationurl:authurl                                                                   keychainitemname:kkeychainitemname                                                                           delegate:self                                                                   finishedselector:@selector(viewcontroller:finishedwithauth:error:)];     [viewcontroller setbrowsercookiesurl:[nsurl urlwithstring:@"http://www.systemurl.co.uk/"]];      // push authentication view our navigation controller instance     [ [self navigationcontroller] pushviewcontroller:viewcontroller animated:yes]; }   - (void)viewcontroller:(gtmoauth2viewcontrollertouch *)viewcontroller       finishedwithauth:(gtmoauth2authentication *)auth                  error:(nserror *)error {     if (error != nil)     {         // authentication failed         uialertview *alertview = [ [uialertview alloc] initwithtitle:@"authorization failed"                                                              message:[error localizeddescription]                                                             delegate:self                                                    cancelbuttontitle:@"dismiss"                                                    otherbuttontitles:nil];         [alertview show];     }     else     {         // authentication succeeded          // assign access token instance property later use         self.accesstoken = auth.accesstoken;          // display access token user         uialertview *alertview = [ [uialertview alloc] initwithtitle:@"authorization succeeded"                                                              message:[nsstring stringwithformat:@"access token: %@", auth.accesstoken]                                                             delegate:self                                                    cancelbuttontitle:@"dismiss"                                                    otherbuttontitles:nil];         [alertview show];     } } 

the issue when run code above redirects me system fine , log in, page comes me grant access app , click "authorize" , app shows me alert view error 500 in it.

so went grails system , looked @ logs see happened , noticed url being passed in app was:

"get /oauth/authorize?client_id=1&redirect_uri=http%3a%2f%2fwww.systemurl.co.uk%2f&response_type=code http/1.1" 302 -  "get /oauth/authorize?client_id=1&redirect_uri=http%3a%2f%2fwww.systemurl.co.uk%2f&response_type=code http/1.1" 200 6923  "post /oauth/authorize?client_id=1&redirect_uri=http%3a%2f%2fwww.systemurl.co.uk%2f&response_type=code http/1.1" 302 - 

and error 500 message shown below system:

2014-03-24 08:25:53,081 [http-8080-2] error errors.grailsexceptionresolver  - nosuchclientexception occurred when processing request: [post] /oauth/token - parameters: client_secret: secret grant_type: authorization_code redirect_uri: http://www.systemurl.co.uk/ code: 4bf5se client_id: 1 no client requested id: testing. stacktrace follows: org.springframework.security.oauth2.provider.nosuchclientexception: no client requested id: testing     @ grails.plugin.cache.web.filter.pagefragmentcachingfilter.dofilter(pagefragmentcachingfilter.java:179)     @ grails.plugin.cache.web.filter.abstractfilter.dofilter(abstractfilter.java:63)     @ grails.plugin.springsecurity.web.filter.grailsanonymousauthenticationfilter.dofilter(grailsanonymousauthenticationfilter.java:53)     @ grails.plugin.springsecurity.web.authentication.requestholderauthenticationfilter.dofilter(requestholderauthenticationfilter.java:49)     @ grails.plugin.springsecurity.web.authentication.logout.mutablelogoutfilter.dofilter(mutablelogoutfilter.java:82)     @ java.lang.thread.run(thread.java:722) 

now error above suggest me reason username being used client id somehow , don't know why, username , password "testing" on grails system.

can please offer advise on why might happening?

thanks in advance


***edit*****


i have debugged http requests being sent , below raw request being sent token:

post /oauth/token http/1.1 host: www.systemurl.co.uk accept-encoding: gzip, deflate content-type: application/x-www-form-urlencoded accept-language: en-us cookie: jsessionid=70eb045c21084e166a34eda88fe155c8.28151 accept: */* content-length: 130 connection: keep-alive user-agent: gtm-oauth2 com.test.oauthgtm/1.0  client_id=1&client_secret=secret&code=vayn8m&grant_type=authorization_code&redirect_uri=http%3a%2f%2fwww.systemurl.co.uk%2f 

the short answer is: "client_id=public", works

the long answer:

if debug through code, you'll find out exception thrown in inmemoryclientdetailsservice.

in grails version 2.2.4 code looks this

private map<string, ? extends clientdetails> clientdetailsstore = new hashmap<string, clientdetails>();    public clientdetails loadclientbyclientid(string clientid) throws oauth2exception {     clientdetails details = clientdetailsstore.get(clientid);     if (details == null) {       throw new invalidclientexception("client not found: " + clientid);     }     return details;   } 

in map clientdetailsstore 1 value "public"


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -