Fel*_*ger 5 ruby authentication ruby-on-rails google-api google-signin
我想使用google-auth-library-ruby gem登录用户。
在他们的指南“服务器端应用程序的 Google 登录”中,他们有一个很好的代码示例,说明如何将授权代码交换为 ID 令牌,但它仅适用于 Python(和 Java):
credentials = client.credentials_from_clientsecrets_and_code(
CLIENT_SECRET_FILE,
['https://www.googleapis.com/auth/drive.appdata', 'profile', 'email'],
auth_code)
Run Code Online (Sandbox Code Playgroud)
有人知道 Ruby 的等价物吗?
附言。我熟悉omniauth gem,但如果可能的话想使用该google-auth-library-rubygem。
经过一番研究,我发现了这组样本,其中googleauth使用了宝石。在这里你有它:
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")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
965 次 |
| 最近记录: |