Sha256: dee4f7355d7a80d8f82f627f891e1290d50e9bbc9068d665f931616036a5a233

Contents?: true

Size: 954 Bytes

Versions: 2

Compression:

Stored size: 954 Bytes

Contents

require 'omniauth-github'

module OmniAuth
  module Strategies
    class CrewCheck < OmniAuth::Strategies::GitHub
      option :name, :crew_check
      option :role_map, {}
      option :role_required, true

      extra do
        {
          :raw_info => raw_info,
          :teams => teams,
          :roles => roles
        }
      end

      def callback_phase
        if options.role_required && roles.empty?
          fail!(:invalid_credentials)
        else
          super
        end
      end

      protected
      def teams
        @teams ||= ::CrewCheck::TeamList.fetch(gh_token)
      end

      def roles
        map = options.role_map.kind_of?(Proc) ? options.role_map.call : options.role_map
        ::CrewCheck::RoleDetermination.new(
          teams.shorthand_names,
          map).roles
      end

      def gh_token
        credentials['token']
      end
    end
  end
end

OmniAuth.config.add_camelization 'crew_check', 'CrewCheck'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
omniauth-crew-check-0.0.3 lib/omniauth/strategies/crew_check.rb
omniauth-crew-check-0.0.2 lib/omniauth/strategies/crew_check.rb