Sha256: 31a68571505be3a7127e44de79dde81e65f1306e6e5f1dcef5c75d48fa8d6095
Contents?: true
Size: 1.13 KB
Versions: 6
Compression:
Stored size: 1.13 KB
Contents
# https://console.developers.google.com # https://developers.google.com/identity/protocols/googlescopes class LuxOauth::Google < LuxOauth def scope [ 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile' ] end def format_response opts { email: opts['email'], name: opts['name'], avatar: opts['picture'], locale: opts['locale'], gender: opts['gender'] } end def login "https://accounts.google.com/o/oauth2/auth?client_id=#{@opts.key}&redirect_uri=#{redirect_url}&scope=#{scope.join('%20')}&response_type=code" end def callback session_code result = RestClient.post('https://www.googleapis.com/oauth2/v3/token', { grant_type: 'authorization_code', client_id: @opts.key, client_secret: @opts.secret, code: session_code, redirect_uri: redirect_url }) hash = JSON.parse(result) user = JSON.parse RestClient.get('https://www.googleapis.com/oauth2/v1/userinfo', { :params => {:access_token => hash['access_token'], :alt=>:json }}) format_response user end end
Version data entries
6 entries across 6 versions & 1 rubygems