假设 user1 已经在我手机的 chrome 浏览器上登录了他的 gmail 帐户。 我正在使用 google rest api 编写一个 android 应用程序,先决条件是 oauth2 授权。如果我从我的应用程序发送授权 url 以在浏览器中打开,则假定 user1 的帐户已通过身份验证并显示授权页面(带有允许/拒绝)按钮。我如何以编程方式注销现有用户,然后从我的应用程序发送 oauth2 url,以便用户明确输入他的凭据并授予 oauth 访问我的应用程序的权限。
我尝试使用以下方式注销但没有成功...
1) https://www.google.com/accounts/logoff?continue=https://accounts.google.com/o/oauth2/v2/auth?redirect_uri=http%3A%2F%2Flocalhost%3A8080&prompt=consent&response_type=code&client_id=blah-blah-blah "&scope="blah blah"
2) https://accounts.google.com/logoff?continue=https://accounts.google.com/o/oauth2/v2/auth?redirect_uri=http%3A%2F%2Flocalhost%3A8080&prompt=consent&response_type=code&client_id=blah-blah-blah "&scope="blah blah"
在选项 2 和 3 中,我收到一个 http 400 错误,指出缺少“response_type”,但它出现在我发送的 url 中。
基本上我的 Intent 是注销现有的 google 用户并明确让我的应用程序的用户登录他的凭据,以便 oauth2 只针对他的帐户而不是其他人(错误地)完成。
最佳答案
我在 http 请求中添加了参数“prompt=select_account+consent”,它对我有用。无论当前登录浏览器的用户是谁,都会为用户显示登录屏幕。
https://accounts.google.com/o/oauth2/v2/auth?prompt=select_account+consent
关于android - oauth2 : Logoff currently logged in google user and then send the oauth url from my app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43413952/