Sha256: b2cdc8ecc61a51f40fcd797b989d05fb1ce8a65bf04a8b551c4cd195472e865a

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

require "omniauth-oauth2"

module OmniAuth
  module Strategies
    class Canvas < OmniAuth::Strategies::OAuth2

      option :name, "Canvas"

      option :client_options, {
        :site           => "https://canvas.instructure.com",
        :authorize_url  => "/login/oauth2/auth",
        :token_url      => "/login/oauth2/token"
      }
      option :token_params, {
        :parse          => :json
      }

      uid do
        access_token['user']['id']
      end

      info do
        {
          'name' => raw_info['name'],
          'email' => raw_info['primary_email'],
          'bio' => raw_info['bio'],
          'title' => raw_info['title'],
          'nickname' => raw_info['login_id'],
          'active_avatar' => raw_info['avatar_url'],
          'token' => access_token.token,
        }
      end

      extra do
        { :raw_info => raw_info }
      end

      def raw_info
        @raw_info ||= access_token.get("/api/v1/users/#{access_token['user']['id']}/profile").parsed
      end

    end
  end
end
OmniAuth.config.add_camelization 'canvas', 'Canvas'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-canvas-0.0.1 lib/omniauth/strategies/canvas.rb