我想使用google-auth-library-ruby gem登录用户。
在他们的指南" Google登录服务器端应用"他们有a good code example如何交换ID令牌的授权代码,但它仅适用于Python(和Java):
credentials = client.credentials_from_clientsecrets_and_code(
CLIENT_SECRET_FILE,
['https://www.googleapis.com/auth/drive.appdata', 'profile', 'email'],
auth_code)
有人知道Ruby的等价物吗?
PS。我熟悉omniauth gem,但如果可能的话,我想使用google-auth-library-ruby
gem。
答案 0 :(得分:1)
经过一番研究,我发现this collection of samples,其中使用了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")