安装应用程序的OAuth 2.0 - 我在哪里获得redirect_uri [英] OAuth 2.0 for Installed Applications - where do I get a redirect_uri

查看:189
本文介绍了安装应用程序的OAuth 2.0 - 我在哪里获得redirect_uri的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照说明使用OAuth2在安装的(Windows)应用程序中访问Gmail,网址 https://developers.google.com/identity/protocols/OAuth2InstalledApp 。这一切似乎很简单,直到我接触到做出令牌请求的部分。我需要做的一个参数是redirect_uri,它表示您从开发者控制台获得的重定向URI。



我已经获得了我的ClientID和ClientSecret从开发者控制台,但看不到任何我从它redirect_uri。



我缺少什么?感谢。

解决方案

身份验证基本上是一个三步或四步的过程

第一步是获取认证码。此链接可以放在任何浏览器窗口中的HTTP GET


https://accounts.google.com/o/oauth2/auth?client_id= {clientid} .apps.googleusercontent.com& redirect_uri = urn :ietf:wg:oauth:2.0:oob& scope = https:// www。 googleapis.com/auth/analytics.readonly&response_type=code


一旦用户接受访问权限,您将获得一个认证码。

该代码被发送回服务器以获取刷新令牌和第一个访问令牌。这是一个HTTP POST。

  https://accounts.google.com/o/oauth2/token 
code = 4 / X9lG6uWd8-MMJPElWggHZRzyFKtp.QubAT_P-GEwePvB8fYmgkJzntDnaiAI& client_id = {ClientId} .apps.googleusercontent.com& client_secret = {ClientSecret}& redirect_uri = urn:ietf:wg:oauth:2.0:oob& grant_type = authorization_code

回复将如下所示

  {
access_token:ya29.1.AADtN_VSBMC2Ga2lhxsTKjVQ_ROco8VbD6h01aj4PcKHLm6qvHbNtn-_BIzXMw,
token_type:承载者,
expires_in:3600,
refresh_token:1 / J-3zPA8XR1o_cXebV9sDKn_f5MTqaFhKFxH-3PUPiJ4
}

访问令牌只能运行一个小时,并且在此之后您将需要使用刷新令牌来获取新的访问令牌。



这也是一个HTTP Post

  https://accounts.google.com/o/oauth2/token 
client_id = {ClientId} .apps .googleusercontent.com& amp; client_secret = {ClientSecret}& refresh_token = 1 / ffYmfI0sjR54Ft9oupubLzrJhD1hZS5tWQcyAvNECCA& grant_type = refresh_token

response



  {
access_token:ya29.1.AADtN_XK16As2ZHlScqOxGtntIlevNcasMSPwGiE3pe5ANZfrmJTcsI3ZtAjv4sDrPDRnQ,
token_type:Bearer ,
expires_in:3600
}

代码已从我的教程谷歌3 lega oauth2 它有比这更多的解释。


I'm working through the instructions to use OAuth2 to get access to Gmail in an installed (Windows) application, on the page https://developers.google.com/identity/protocols/OAuth2InstalledApp. It all seems straightforward until I get to the part about "making a token request". One of the parameters to the POST I have to do is redirect_uri, which it says is "The redirect URI you obtained from the Developers Console."

I have obtained my ClientID and ClientSecret from the Developers Console, but can't see anywhere that I get a redirect_uri from it.

What am I missing? Thanks.

解决方案

Authentication is baslicy a three or four step process

Step one is just getting the authentication code. this link can be placed in any browser window its a HTTP GET

https://accounts.google.com/o/oauth2/auth?client_id={clientid}.apps.googleusercontent.com&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/analytics.readonly&response_type=code

Once the user has accepted access you will be given an authentication code.

That code is sent back to the server to get a refresh token and the first access token. this is a HTTP POST.

https://accounts.google.com/o/oauth2/token
code=4/X9lG6uWd8-MMJPElWggHZRzyFKtp.QubAT_P-GEwePvB8fYmgkJzntDnaiAI&client_id={ClientId}.apps.googleusercontent.com&client_secret={ClientSecret}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code

The response will be something like this

{
"access_token" : "ya29.1.AADtN_VSBMC2Ga2lhxsTKjVQ_ROco8VbD6h01aj4PcKHLm6qvHbNtn-_BIzXMw",
"token_type" : "Bearer",
"expires_in" : 3600,
"refresh_token" : "1/J-3zPA8XR1o_cXebV9sDKn_f5MTqaFhKFxH-3PUPiJ4"
}

The access token will only work for one hour and it will expire after that you will need to use the refresh token to get a new access token.

This is also a HTTP Post

https://accounts.google.com/o/oauth2/token
client_id={ClientId}.apps.googleusercontent.com&client_secret={ClientSecret}&refresh_token=1/ffYmfI0sjR54Ft9oupubLzrJhD1hZS5tWQcyAvNECCA&grant_type=refresh_token

response

{
"access_token" : "ya29.1.AADtN_XK16As2ZHlScqOxGtntIlevNcasMSPwGiE3pe5ANZfrmJTcsI3ZtAjv4sDrPDRnQ",
"token_type" : "Bearer",
"expires_in" : 3600
}

code has been ripped from my tutorial Google 3 legged oauth2 it has more explanation than this.

这篇关于安装应用程序的OAuth 2.0 - 我在哪里获得redirect_uri的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆