让谷歌的OAuth认证令牌Android-返回与invalid_scope /未知错误 [英] getting Google oauth authorization token from Android- return with invalid_scope/ Unknown error

查看:1196
本文介绍了让谷歌的OAuth认证令牌Android-返回与invalid_scope /未知错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用谷歌的OAuth在我的Andr​​oid应用程序验证用户身份。 然后,我想将它发送到我的应用程序服务器,以便它可以连接在任何时间与谷歌日历。

I try to use Google oauth to authenticate users on my android app. Then I would like to send it to my app server so it can connect at any time with Google calendar.

我试图用       GoogleAuthUtil.getToken(getApplicationContext(),mAccountName,mScope);

I tried to use GoogleAuthUtil.getToken(getApplicationContext(), mAccountName, mScope);

下面这篇文章: <一href="https://developers.google.com/accounts/docs/CrossClientAuth">https://developers.google.com/accounts/docs/CrossClientAuth

当我使用它的适用范围 mScope =oauth2如下:https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth /userinfo.profile; 我得到一个令牌,有效期为一小时

When I use it with scope mScope = "oauth2:https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"; I get a token, which is valid for an hour

但是,当我尝试获得授权code(这样我就可以得到一个刷新令牌的有效期为更长的时间,用 mScope2 =oauth2:服务器:CLIENT_ID:{} CLIENT_ID .apps.googleusercontent.com+:api_scope如下:https://www.googleapis.com/auth/calendar的https://www.googleapis .COM /认证/ userinfo.email https://www.googleapis.com/auth/userinfo.profile;

But when I try to get an authorization code (so I can get a refresh token that is valid for longer time, using mScope2 ="oauth2:server:client_id:{CLIENT_ID}.apps.googleusercontent.com"+ ":api_scope:https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile";

我收到任何invalid_scope或未知的例外。

I receive either "invalid_scope" or "Unknown" exceptions.

我是什么做错了吗?

编辑: OK,建立在谷歌API控制台新的应用程序,并添加plus.login的范围后,我收到了code,但由于某些原因,我的服务器无法解析此标记。当绑解析服务器获取有关重定向URL错误。 顺便说一句,当我做它的工作原理相同参数的网络流量。

OK, After creating a new app on google API console and adding plus.login to the scope I get a code, but for some reason my server can't resolve this token. When tying to resolve server gets an error about the redirection URL. BTW, When I do the web flow with same parameters it works.

推荐答案

OK,找到了解决办法,我希望谷歌拥有约与谷歌的Oauth和Android的工作好了很多文件。你有几件事情要知道与Android和离线令牌工作

OK, found the solution, I expected Google to have a lot better documentation about working with Google Oauth and Android. A few things you have to know to work with Android and offline token

  1. 在创建谷歌的客户端ID,你创建Web应用程序之前,不要创建服务应用程序

  1. When you create google Client ID Don't create a service application before you create a web application

必须包括 https://www.googleapis.com/auth/plus.login 在你的范围

最奇怪,解决我的服务器上的一次性授权code,我不得不使用来自Android客户端ID信息重定向URL(它甚至没有看起来像一个URL),而不是从在谷歌API控制台的Web客户端的详细信息。

The weirdest, to resolve the one time authorization code on my server, I had to use the redirection URL from the Android client ID details (which doesn't even look like a url) and not from the Web client details on Google API console.

这篇关于让谷歌的OAuth认证令牌Android-返回与invalid_scope /未知错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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