Sha256: 4972e5215a56c385f94db1846085baa77d061463521cc758b5f365953b1e7594

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

require "omniauth-oauth2"
require "jwt"

module OmniAuth
  module Strategies
    class EveOnlineSso < OmniAuth::Strategies::OAuth2
      option :name, "eve_online_sso"

      option :client_options,
        authorize_url: "/v2/oauth/authorize",
        token_url: "/v2/oauth/token",
        site: "https://login.eveonline.com/"

      uid { raw_info["character_id"] }

      info do
        {
          name: raw_info["name"],
          character_id: raw_info["character_id"],
          expires_on: raw_info["expires_on"],
          scopes: raw_info["scopes"],
          token_type: raw_info["token_type"],
          character_owner_hash: raw_info["owner"]
        }
      end

      extra do
        {
          raw_info: raw_info
        }
      end

      def raw_info
        @raw_info ||= JWT.decode(access_token.token, nil, false)
          .find { |element| element.keys.include?("scp") }.tap do |hash|
          hash["character_id"] = hash["sub"].split(":")[-1]
          hash["scopes"] = hash["scp"].join(" ")
          hash["token_type"] = hash["sub"].split(":")[0].capitalize
          hash["expires_on"] = hash["exp"]
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-eve_online-sso-0.4.0 lib/omniauth/strategies/eve_online_sso.rb