Sha256: fa9870f9a14a903e253a1721fb1880ebdc5ad55c221ce6f75c84013ffdab0aae

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

require 'omniauth-oauth2'
require 'json'

module OmniAuth
  module Strategies
    class Line < OmniAuth::Strategies::OAuth2
      option :name, 'line'
      option :scope, 'profile openid email'

      option :client_options, {
        site: 'https://access.line.me',
        authorize_url: '/oauth2/v2.1/authorize',
        token_url: '/oauth2/v2.1/token'
      }

      def callback_phase
        options[:client_options][:site] = 'https://api.line.me'
        super
      end

      alias :old_callback_url :callback_url
      
      def callback_url
        if request.params['callback_url']
          request.params['callback_url']
        else
          old_callback_url
        end
      end

      def callback_path
        params = session['omniauth.params']

        if params.nil? || params['callback_url'].nil?
          super
        else
          URI(params['callback_url']).path
        end
      end
      
      uid { raw_info['userId'] }

      info do
        {
          name:        raw_info['displayName'],
          email:       raw_info['email'],
          image:       raw_info['pictureUrl'],
          description: raw_info['statusMessage']
          info:        raw_info
        }
      end

      def raw_info
        @raw_info ||= JSON.load(access_token.get('v2/profile').body)
      rescue ::Errno::ETIMEDOUT
        raise ::Timeout::Error
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-ljne-0.1.4 lib/omniauth/strategies/line.rb