我想用 google-auth-library-ruby 登录用户 gem 。
在他们的指南“服务器端应用程序的 Google 登录”中,他们有 a good code example如何交换 ID token 的授权代码,但它仅适用于 Python(和 Java):
credentials = client.credentials_from_clientsecrets_and_code(
CLIENT_SECRET_FILE,
['https://www.googleapis.com/auth/drive.appdata', 'profile', 'email'],
auth_code)
有人知道 Ruby 的等价物吗?
附言。我熟悉 omniauth gem,但如果可能,我想使用 google-auth-library-ruby
gem。
最佳答案
经过一些研究,我找到了this collection of samples ,其中使用了 googleauth
gem。给你:
client_id = Google::Auth::ClientId.new("your Google client ID", "your Google secret")
scope = ["email","profile"]
token_store = nil # there are actually already implemented File or Redis token stores
callback_url = "http://localhost:8000"
authorizer = Google::Auth::UserAuthorizer.new(client_id, scope, token_store, callback_url)
credentials = authorizer.get_credentials_from_code(code: "the auth code in the Sign In response")
关于ruby-on-rails - 使用适用于 Ruby 的 Google Auth 库登录用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47519849/