Sha256: 3e86e922995158047515a90bad25f4f4a1772c1ed7da331a6de0365c0aaab52d

Contents?: true

Size: 949 Bytes

Versions: 5

Compression:

Stored size: 949 Bytes

Contents

require 'omniauth'
require 'omniauth-oauth2'

module OmniAuth
  module Strategies
    class Openstax < OAuth2
      option :name, "openstax"

      option :client_options, {
        :site => "http://accounts.openstax.org",
        :authorize_url => "/oauth/authorize"
      }

      uid { raw_info["id"] }

      info do
        username = raw_info["username"]
        title = raw_info["title"]
        first_name = raw_info["first_name"]
        last_name = raw_info["last_name"]
        full_name = raw_info["full_name"] || "#{first_name} #{last_name}"
        full_name = username if full_name.blank?

        # Changed to conform to the omniauth schema
        {
          name: full_name,
          nickname: username,
          first_name: first_name,
          last_name: last_name,
          title: title
        }
      end

      def raw_info
        @raw_info ||= access_token.get('/api/users/me.json').parsed
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
openstax_accounts-0.3.0 lib/omniauth/strategies/openstax.rb
openstax_accounts-0.3 lib/omniauth/strategies/openstax.rb
openstax_accounts-0.2.1 lib/omniauth/strategies/openstax.rb
openstax_accounts-0.2.0 lib/omniauth/strategies/openstax.rb
openstax_accounts-0.1.0 lib/omniauth/strategies/openstax.rb