Results 1 to 8 of 8

Thread: Access token as part of a response when using JavaScript client

  1. #1
    Join Date
    Jul 2012
    Posts
    4

    Default Access token as part of a response when using JavaScript client

    Hi guys,

    I have a question about the jso.js JavaScript client implementation and server-side token provider. Is it possible to have all OAuth2 token access details as part of a response and not as URL parameters? I guess I have to provide a custom filter for that but for the moment I don't see which one exactly. I would like to avoid redirecting the (JavaScript) client request and simply provide the next token value in the response.

    Thanks in advance!

    Ivan
    Last edited by iv.hristov; Jul 24th, 2012 at 04:18 PM.

  2. #2
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    You mean URL fragments (not URL parameters)?

    I don't think there's anything stopping a JavaScript client from using the authorization code grant type. Haven't tried it myself, and it might not be supported by the library you are using. But that might be the easiest way to get the token in the response body - use the token endpoint.

    If you want a server-side solution you need to look at the AuthorizationEnpoint. If you register your own implementation with a @RequestMapping for /oauth/authorize it should take precedence over the framework one, so that would be the place to start probably.

  3. #3
    Join Date
    Jul 2012
    Posts
    4

    Default

    Hi Dave,

    As a JavaScript client I'm using the oajax implementation found in jso.js on spring-security-oauth git repo. I don't see how to specify using authorization code grant type in the client. Do you know of any other JavaScript client implementations?

    Thanks for the hint about the /oauth/authorize precedence. In deed, I was just pondering how to hook-in the AuthorizationEndpoint.

    As for the URL, I mean the URL parameters separated by ampersands:
    &access_token=ad12bea2-6d14-480f-820c-56e811aa8861&token_type=bearer&state=7f522c50-4392-450a-83ff-9463ef2ea566&expires_in=37179

    which are appended to the redirect URL. What do you mean by URL fragments? I didn't see any # fragments being added to the URL.

  4. #4
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    For an implicit grant there should be a fragment separator. Are you sure it's not there?

    I don't know of any fully-baked JavaScipt libraries. Scott Andrews was working on something but he may have been distracted. Ping him on twitter @scothis.

  5. #5
    Join Date
    Jul 2012
    Posts
    4

    Default

    I have a fragment separator in my redirect_uri (as part of my target uri), but I can see in the console a DEBUG message from FilterChainProxy where the redirect_uri is well encoded so there are no fragment separators. How should I specify the authorization code grant type when doing the request?

  6. #6
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    Per the spec you send response_type=token to the authorization endpoint. The JSO library should be doing that work you. Maybe if your redirect already has a fragment there is a bug in the endpoint, but I hope not. What does your client see in the response location header?

  7. #7
    Join Date
    Jul 2012
    Posts
    4

    Default

    Indeed, the JSO does the job with the response_type=token, I can see it in the logs. In the response location header I see:

    http://localhost:8080/webapp/#menu&a...pires_in=43199

    Looking at the draft version of the standard, I see that the client will always be redirected. So I guess I can't simply initialize my access_token by asking the server to give me all the OAuth2 details in a response body.

    What happens once the access token expires? Is the JSO client going to refresh it? On the server-side if I like to tune the token expiration how should I do ti correctly?

  8. #8
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    I don't know how JSO handles expiry. I assume it grabs a new token (the same flow).

    On the server side there are two settings you can configure: a global property of the *TokenServices, plus every client has their own value taht overrides the global setting if used. For more complicated logic you would provide a custom AuthorizationServerTokenServices.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •