Sha256: d84b50308560c4d5a6a1b93c5a41659a95c2278601e7113ae4731522b1522101
Contents?: true
Size: 1.43 KB
Versions: 5
Compression:
Stored size: 1.43 KB
Contents
class OauthGg < Oauth def auth_request step = :step1, add_params = nil uri = URI CONFIG[:oauth][@name][:auth][step][:uri] params = CONFIG[:oauth][@name][:auth][:united_params].merge(CONFIG[:oauth][@name][:auth][step].except(:uri)).merge({redirect_uri: @verify_url, state: @key}) # для второго шага params.merge!(add_params) unless add_params.nil? case step when :step1 uri.query = URI.encode_www_form params uri.to_s when :step2 oauth_access_card_params Net::HTTP.post_form uri, params end end def oauth_access_card_params result begin params = ActiveSupport::JSON.decode(result.body) unless params['error'].present? add_info = token_info({id_token: params['id_token']}) { state: :ok, oauth_name: @name, oauth_uid: add_info['sub'], access_token: params['access_token'], token_expired: (DateTime.now + params['expires_in'].second).to_s(:db), photourl: add_info['picture'] } else error_response params['error'] end rescue Exception => error error_response error.message end end def token_info access_params uri = URI CONFIG[:oauth][@name][:api][:tokeninfo][:uri] params = access_params uri.query = URI.encode_www_form params result = Net::HTTP.get_response uri ActiveSupport::JSON.decode(result.body) end end
Version data entries
5 entries across 5 versions & 1 rubygems