我们有一些应用程序(或者我们应该称它们为一小撮脚本)使用Google来简化一些管理任务。最近,在同一个项目中创建了另一个client_id之后,我开始收到一个类似于请求错误)中描述的错误消息。也就是说,
错误400: invalid_request 你不能登录这个应用程序,因为它不符合谷歌的OAuth 2.0政策,以确保应用程序的安全。 您可以让应用程序开发人员知道这个应用程序不符合一个或多个Google验证规则。 请求详细信息: 本节中的内容由应用程序开发人员提供。谷歌尚未对此内容进行审查或验证。 如果您是应用程序开发人员,请确保这些请求细节符合谷歌的政策。 redirect_uri: urn:ietf:wg:oauth:2.0:oob
如何克服这个错误?必须指出的是:
urn:ietf:wg:oauth:2.0:oob
重定向URI (复制/粘贴是在没有浏览器的无头计算机上运行的唯一友好方式)。下面是围绕授权流的代码部分,不同客户端ID的URL是在$stderr.puts url
行上生成的。这与在这里的官方例子中有记载 (本文撰写时的版本)几乎是一样的。
OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'
def user_credentials_for(scope, user_id = 'default')
token_store = Google::Auth::Stores::FileTokenStore.new(:file => token_store_path)
authorizer = Google::Auth::UserAuthorizer.new(client_id, scope, token_store)
credentials = authorizer.get_credentials(user_id)
if credentials.nil?
url = authorizer.get_authorization_url(base_url: OOB_URI)
$stderr.puts ""
$stderr.puts "-----------------------------------------------"
$stderr.puts "Requesting authorization for '#{user_id}'"
$stderr.puts "Open the following URL in your browser and authorize the application."
$stderr.puts url
code = $stdin.readline.chomp
$stderr.puts "-----------------------------------------------"
credentials = authorizer.get_and_store_credentials_from_code(
user_id: user_id, code: code, base_url: OOB_URI)
end
credentials
end
发布于 2022-03-02 19:11:19
我发了一封电子邮件给Google OAuth团队的人。这是他们回应的要点。
因为我担心你的问题与使用更安全的OAuth流使Google OAuth交互更加安全有关
谷歌目前的建议是,按照这里的建议,使用localhost/环回重定向:如果您使用的是非敏感作用域,并且需要无头解决方案,则可以使用指示-oob或对设备流使用OAuth。
发布于 2022-03-03 02:48:42
对于这种情况,这里有一个令人畏惧的解决办法:
在问题中发布的代码中将urn:ietf:wg:oauth:2.0:oob
替换为http://localhost:1/
。这使得流程通过,我的浏览器被重定向并失败,我得到了如下错误消息:
This site can’t be reached
The webpage at http://localhost:1/oauth2callback?
code=4/a3MU9MlhWxit8P7N8QsGtT0ye8GJygOeCa3MU9MlhWxit8P7N8QsGtT0y
e8GJygOeC&scope=email%20profile%20https... might be temporarily
down or it may have moved permanently to a new web address.
ERR_UNSAFE_PORT
现在,从失败的URL复制代码code
值,将其粘贴到应用程序中,然后查看.(与以前相同:)
P.S.以下是更新的“工作”版本:
def user_credentials_for(scope, user_id = 'default')
token_store = Google::Auth::Stores::FileTokenStore.new(:file => token_store_path)
authorizer = Google::Auth::UserAuthorizer.new(client_id, scope, token_store, "http://localhost:1/")
credentials = authorizer.get_credentials(user_id)
if credentials.nil?
url = authorizer.get_authorization_url
$stderr.puts ""
$stderr.puts "-----------------------------------------------"
$stderr.puts "Requesting authorization for '#{user_id}'"
$stderr.puts "Open the following URL in your browser and authorize the application."
$stderr.puts url
$stderr.puts
$stderr.puts "At the end the browser will fail to connect to http://localhost:1/?code=SOMECODE&scope=..."
$stderr.puts "Copy the value of SOMECODE from the address and paste it below"
code = $stdin.readline.chomp
$stderr.puts "-----------------------------------------------"
credentials = authorizer.get_and_store_credentials_from_code(
user_id: user_id, code: code)
end
credentials
end ```
发布于 2022-03-18 09:06:22
蟒蛇的解决方案。
正如奥特利布所显示的,在2022年2月28日之后,InstalledAppFlow.run_console
已经被废弃。如果您使用的是谷歌-广告-python,您只需用flow.run_local_server()
替换flow.run_console()
即可。
https://stackoverflow.com/questions/71318804
复制相似问题