Google Oauth-2.0 returns url 使用哈希而不是问号
Google Oauth-2.0 returns url with hash instead of question mark
我使用此表单请求 Google 离线令牌
<form action="https://accounts.google.com/o/oauth2/auth" methode="POST">
<input type="hidden" name="access_type" value="offline" />
<input type="hidden" name="client_id" value="XXX" />
<input type="hidden" name="scope" value="https://www.googleapis.com/auth/analytics https://www.googleapis.com/auth/analytics.edit https://www.googleapis.com/auth/analytics.manage.users https://www.googleapis.com/auth/analytics.manage.users.readonly https://www.googleapis.com/auth/analytics.readonly" />
<input type="hidden" name="response_type" value="code token gsession" />
<input type="hidden" name="redirect_uri" value="http://example.com/analytics" />
<input type="hidden" name="approval_prompt" value="force" />
<button>Get or Refresh token</button>
</form>
怎么 Google 给我回了一个 URL 像 :
http://example.com/analytics#access_token=XXX&token_type=Bearer&expires_in=3600&code=YYY&authuser=0&num_sessions=1&prompt=consent&session_state=ZZZ
请注意,在主要 url 部分之后,我们有一个哈希码 #
而不是问号 ?
。
我希望通过 PHP $_GET
获得上述变量,但我不能,因为那个哈希码。
我的问题是如何获得带问号的 url?
您正在使用 code token gsession
的 response_type
触发所谓的 Implicit
流程,其中 access_token
将在 [=20= 】片段。使用 response_type=code
获取 code
值作为查询参数,您可以在令牌端点使用该值将其交换为 access_token
,如以下所述:https://developers.google.com/accounts/docs/OAuth2WebServer#handlingtheresponse
我使用此表单请求 Google 离线令牌
<form action="https://accounts.google.com/o/oauth2/auth" methode="POST">
<input type="hidden" name="access_type" value="offline" />
<input type="hidden" name="client_id" value="XXX" />
<input type="hidden" name="scope" value="https://www.googleapis.com/auth/analytics https://www.googleapis.com/auth/analytics.edit https://www.googleapis.com/auth/analytics.manage.users https://www.googleapis.com/auth/analytics.manage.users.readonly https://www.googleapis.com/auth/analytics.readonly" />
<input type="hidden" name="response_type" value="code token gsession" />
<input type="hidden" name="redirect_uri" value="http://example.com/analytics" />
<input type="hidden" name="approval_prompt" value="force" />
<button>Get or Refresh token</button>
</form>
怎么 Google 给我回了一个 URL 像 :
http://example.com/analytics#access_token=XXX&token_type=Bearer&expires_in=3600&code=YYY&authuser=0&num_sessions=1&prompt=consent&session_state=ZZZ
请注意,在主要 url 部分之后,我们有一个哈希码 #
而不是问号 ?
。
我希望通过 PHP $_GET
获得上述变量,但我不能,因为那个哈希码。
我的问题是如何获得带问号的 url?
您正在使用 code token gsession
的 response_type
触发所谓的 Implicit
流程,其中 access_token
将在 [=20= 】片段。使用 response_type=code
获取 code
值作为查询参数,您可以在令牌端点使用该值将其交换为 access_token
,如以下所述:https://developers.google.com/accounts/docs/OAuth2WebServer#handlingtheresponse