我目前正在开发Google Api跨客户端授权的Web组件,如本文所述. https://developers.google.com/identity/protocols/CrossClientAuth
此外,我所处的环境是Rails,因此我使用的是google-api-client gem,如本文所述https://developers.google.com/identity/protocols/OAuth2WebServer#handlingtheresponse
授权代码通过Android应用程序使用Web客户端ID获取并传递到Web api以进行交换.我使用gem和代码进行交换如下
auth_client = Google::APIClient::ClientSecrets.load("/path/to/client_secrets.json").to_
authorization
auth_client.code = code
auth_client.fetch_access_token!
Run Code Online (Sandbox Code Playgroud)
我还试过了
auth_client = Google::APIClient::ClientSecrets.load("/path/to/client_secrets.json").to_
authorization
auth_client.update!(
:grant_type => 'authorization_code'
)
auth_client.code = code
auth_client.fetch_access_token!
Run Code Online (Sandbox Code Playgroud)
在任何情况下,我都会收到来自Google的无效授权错误,但没有说明.
我试图构建网址,以利用其他api工具,如卷曲和邮差,并绕过宝石,使用谷歌oauth游乐场,没有任何成功.
任何洞察可能产生无效授权错误的内容或如何生成curl请求以直接与geogle外部的google交换令牌将非常感激.
我正在尝试Heroku的新"Heroku Review Apps"功能.每当您在github中为给定项目创建新的拉取请求时,它都会创建一个新的Heroku应用程序.
我正在尝试让Google OAuth2支持他们,但每个创建的应用都有一个新的URL.例如https://my-app-pr-124.herokuapp.com
问题是,当用户尝试登录此新应用时,Google将不允许将用户重定向回应用,因为Google尚未信任该网址.
我可以在我的应用中添加自己的Google API密钥,并在部署时运行脚本,但是如何通知Google这个新网址应该受信任重定向?
我的Android应用程序当前使用GoogleAuthUtil来登录用户并获取access_token传递给后端的代码段(下面的代码片段显示创建GoogleApiClient并使用GoogleAuthUtil获取令牌).
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(new Scope("profile"))
.build();
...
...
String accessToken = GoogleAuthUtil.getToken(GoogleLoginActivity.this,
Plus.AccountApi.getAccountName(mGoogleApiClient),
"oauth2:profile email");
Run Code Online (Sandbox Code Playgroud)
然后我发送到后端
我现在正在尝试迁移到新的Google SignIn - https://developers.google.com/identity/sign-in/android/sign-in
所以改变了GoogleApiClient的创作,比如
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestIdToken("<web client id>")
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
Run Code Online (Sandbox Code Playgroud)
然后进行登录使用,
startActivityForResult(Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient), RC_GET_TOKEN);
Run Code Online (Sandbox Code Playgroud)
和活动结果使用(类似于上面链接中的示例),
OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
if (opr.isDone()) {
// If the user's cached credentials are valid, the OptionalPendingResult will be "done"
// and the GoogleSignInResult will be available instantly.
Log.d(TAG, …Run Code Online (Sandbox Code Playgroud) android google-login oauth-2.0 google-play-services google-oauth2
好吧,由于其他问题(已解决)仍未解决,我打算使用POSTMan对客户端库执行的每个步骤进行试验和错误.
所以我再次阅读了Google OAuth2 的基本步骤,在Api Manager中创建了另一个OAuth 2 ID >在Dev Console中创建了凭据,ID类型是Web应用程序,并将它们填充到POSTMan中:
我错过了什么吗?
(可以在此处找到Google重定向URI )
(API范围可以在这里找到)
对于一个项目,有人给了我这个我在Postman中用于测试目的的数据:
在Postman中,这非常有效.
身份验证网址:https://api.example.com/oauth/access_token
访问令牌网址:https
://api.example.com/access_token
客户端ID:abcde 客户端密码:12345
令牌名称:access_token
授权类型:客户端凭据
我只需要取回访问令牌.
有一次,我得到了访问令牌,我可以继续.
我已经尝试了几个Python包和一些自定义代码,但不知怎的,这个看似简单的任务开始引起真正的麻烦.
我试过一个例子:
import httplib
import base64
import urllib
import json
def getAuthToken():
CLIENT_ID = "abcde"
CLIENT_SECRET = "12345"
TOKEN_URL = "https://api.example.com/oauth/access_token"
conn = httplib.HTTPSConnection("api.example.com")
url = "/oauth/access_token"
params = {
"grant_type": "client_credentials"
}
client = CLIENT_ID
client_secret = CLIENT_SECRET
authString = base64.encodestring('%s:%s' % (client, client_secret)).replace('\n', '')
requestUrl = url + "?" + urllib.urlencode(params)
headersMap = {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Basic " + authString
}
conn.request("POST", requestUrl, …Run Code Online (Sandbox Code Playgroud) 我一直试图从谷歌api使用谷歌客户端"代码"从谷歌客户端返回刷新令牌.它返回我发送到服务器端的代码.现在从服务器端我发送代码以使用google-api-php-client通过此调用获取刷新令牌和访问令牌:
https://www.googleapis.com/oauth2/v4/token
Run Code Online (Sandbox Code Playgroud)
虽然我使用谷歌操场上相同的代码我也得到了刷新令牌的响应,但我没有从我自己的服务器得到它..这是代码
public function getRefreshToken($code)
{
$client = new Google_Client();
$client->setClientId(config('services.google.client_id'));
$client->setClientSecret(config('services.google.client_secret'));
$client->setRedirectUri('postmessage');
$client->setScopes(config('services.google.scopes'));
$client->setAccessType("offline");
$client->setApprovalPrompt("force");
dd($client->authenticate($code));
dd($client->getRefreshToken());
return ;
}
Run Code Online (Sandbox Code Playgroud)
我已经将访问类型设置为离线,如某些答案中所述,但我仍然使用刷新令牌获得响应.这是响应
access_token :"xxxxxxxxxxxxxxxxxxxxxx"
created:1510242052
expires_in:3598
id_token:"xxxxxxxx"
token_type:"Bearer"
Run Code Online (Sandbox Code Playgroud) javascript php google-authentication google-api-php-client google-oauth2
A) <script src="https://apis.google.com/js/platform.js"></script>
Run Code Online (Sandbox Code Playgroud)
与
B) <script src="https://apis.google.com/js/api.js"></script>
Run Code Online (Sandbox Code Playgroud)
我应该使用平台脚本还是api脚本,对如何使用Google OAuth服务有些困惑。
当我使用多个帐户登录谷歌时

我试图通过https://stackoverflow.com/users/login(或使用OAuth2的任何其他网站)授权自己

我得到了 Bad Request - Error 400

当我处于隐身模式时,这不会发生

样本请求如下
https://accounts.google.com/o/oauth2/auth?client_id=717762328687-p17pldm5fteklla3nplbss3ai9slta0a.apps.googleusercontent.com&scope=profile+email&redirect_uri=https%3a%2f%2fstackauth.com%2fauth%2foauth2%2fgoogle&state=%7b%22sid%22%3a1%2c%22st%22%3a%221435c1882569148a8513b8e5ba7f747ac7821aaf558cbb1a28dd11c5c3cb358b%22%2c%22ses%22%3a%22354093ee65ee44e8a24582c78bdb7127%22%7d&response_type=code
Run Code Online (Sandbox Code Playgroud)
还有其他类似的问题,如Google oauth2和400个不良请求:谷歌方面的Bug?但是旧的并标记为固定的错误.我怎么能解决这个问题?我应该添加一些其他参数来触发帐户选择吗?
我最近安装了Ngrok,以便在手机上测试我的localhost流星应用程序.我成功通过ngrok通过隧道访问流星应用程序.但是,当我尝试登录时,我收到此错误消息:
登录过程显示以下错误消息:
400. That’s an error.
Error: redirect_uri_mismatch
Application: AppName
You can email the developer of this application at: my@emailadress.com
The redirect URI in the request, http://localhost:7123/_oauth/google,
does not match the ones authorized for the OAuth client.
Run Code Online (Sandbox Code Playgroud)
更新授权的JavaScript源并将URI重定向到Ngrok转发地址,没有任何效果.
如何正确使用ngrok与Google Oauth结合使用?
任何帮助将不胜感激
我使用户登录到通过我自己的OAuth2 API自己的Chrome扩展,它使用谷歌登入,通过chrome.identity.launchWebAuthFlow与interactive设置为true,并能正常工作,系统会提示用户与谷歌帐户登录,我得到了我的分机的背景脚本重定向URL解析访问来自它的令牌,一切正常,直到我需要注销该用户并使其可以与其他帐户签名.当我尝试再次chrome.identity.launchWebAuthFlow使用interactiveset 运行true时,没有任何内容弹出,但重定向url在后台返回,并且为先前登录的用户选择了访问令牌,因此我无法让我的用户切换帐户.
这有什么解决方案吗?
google-oauth2 ×10
google-oauth ×3
oauth-2.0 ×3
google-api ×2
javascript ×2
android ×1
google-login ×1
heroku ×1
meteor ×1
ngrok ×1
php ×1
postman ×1
python ×1
ruby ×1