OAuth2: query string vs. fragment

Just noticed that in OAuth2 when the requested grant type is: "code" the callback contains it in the query string parameters (after '?'). However, when the grant is "token" it is passed as a fragment (after '#').

This looks to be part of a spec (http://tools.ietf.org/html/draft-ietf-oauth-v2-26#section-4.2)

What could be a rationale behind such decision?

Thanks, Piotr


When your browser gets redirected by a website to a URL with a query parameter, the query string is also part of the request that your browser now sends to the host. Fragments are only evaluated locally by your web browser and not included into the request to the host.

In case of the Authorization Code Grant , where you typically have a web application, that directly talks to a provider, sending the data to the host is exactly what you need:

  • The web application redirects your browser to the provider where you log in.
  • The provider now tells your browser a callback URL of the web application and appends an authorization code. This code has to be sent to the web application, so it is included as a query parameter into the request to the callback URL.
  • The web application now itself talks to the provider in the background and verifies with the authorization code that he is indeed allowed to query the provider for an access token.
  • In case of the Implicit Grant , you typically have some Javascript application directly running in your browser. There's no need to pass any authorization code to the host and in most cases there's also no need to send the access token to the host, as the JS in the browser can directly talk to the provider. This way you could eg create a website on a server that uses information queried from another provider with consent from the user where the server never gets access to any confidential data of the user. (In case of a trusted website, that doesn't send the access token to the server.)

    链接地址: http://www.djcxy.com/p/48008.html

    上一篇: 如何在Android上使用MAC访问验证签名标题?

    下一篇: OAuth2:查询字符串与片段