Sha256: 1723b766f92c495adf6df8cf033f25dc7d798928eb32637e2782f87f6e7facde

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

require 'omniauth-oauth2'

module OmniAuth
  module Strategies
    class Identitas < OmniAuth::Strategies::OAuth2
      # change the class name and the :name option to match your application name
      option :name, :identitas

      option :client_options, {
        site: "https://api.identitas.com",
        authorize_url: "/oauth/authorize"
      }

      uid { raw_info["id"] }

      info do
        {
          email: raw_info["email"],
          first_name: raw_info["first_name"],
          last_name: raw_info["last_name"],
          name: [raw_info["first_name"], raw_info["last_name"]].join(" ")
        }
      end

      extra do
        hash = {}
        hash['raw_info'] = raw_info unless skip_info?
        hash['m'] = request.params["m"]
        hash['application_info'] = application_info
        hash
      end

      def raw_info
        @raw_info ||= access_token.get('/v1/me.json').parsed
      rescue ::Errno::ETIMEDOUT
        raise ::Timeout::Error
      end

      # # https://github.com/intridea/omniauth-oauth2/issues/81
      def callback_url
        full_host + script_name + callback_path + check_if_mobile
      end

      def check_if_mobile
        "?" + {m: options.authorize_params[:m]}.to_query
      end

      def setup_phase
        options.authorize_params[:m] = request.params["m"]
      end

      def application_info
        @application_info ||= access_token.get('/v1/app/info').parsed
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-identitas-0.2.2 lib/omniauth/strategies/identitas.rb