Sha256: 7d1b3e33aa9b11ba597a103b20e26b675af474c8b9810e2cba9038a05cfc6b87

Contents?: true

Size: 982 Bytes

Versions: 2

Compression:

Stored size: 982 Bytes

Contents

module Applicaster
  class Accounts
    attr_accessor :client_id
    attr_accessor :client_secret

    class << self
      def default_site
        "http://accounts2.applicaster.com"
      end

      def site
        URI.parse(ENV["ACCOUNTS_BASE_URL"] || default_site)
      end
    end

    def initialize(client_id, client_secret)
      @client_id = client_id
      @client_secret = client_secret
    end

    def user_data_from_omniauth(omniauth_credentials)
      access_token(omniauth_credentials).get("/api/v1/users/current.json").parsed
    end

    def client
      @client ||= ::OAuth2::Client.new(
        client_id,
        client_secret,
        site: Applicaster::Accounts.site,
        authorize_url: "/oauth/authorize",
      )
    end

    def access_token(omniauth_credentials)
      @access_token ||= OAuth2::AccessToken.new(
        client,
        omniauth_credentials["token"],
        omniauth_credentials.except("token", "expires"),
      )
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
omniauth-applicaster-1.0.1 lib/applicaster/accounts.rb
omniauth-applicaster-1.0.0 lib/applicaster/accounts.rb