From 9987c820f9997d46e07979f4f259e466154e9d2e Mon Sep 17 00:00:00 2001 From: Ilya Zverev Date: Thu, 6 Apr 2017 17:07:18 +0300 Subject: [PATCH] New passport server --- lib/omniauth-mapsme/version.rb | 2 +- lib/omniauth/strategies/mapsme-base.rb | 20 +++++++++++++++++++- lib/omniauth/strategies/mapsme-token.rb | 8 ++++---- lib/omniauth/strategies/mapsme.rb | 8 ++++---- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/lib/omniauth-mapsme/version.rb b/lib/omniauth-mapsme/version.rb index fd444a8..ece4bac 100644 --- a/lib/omniauth-mapsme/version.rb +++ b/lib/omniauth-mapsme/version.rb @@ -1,6 +1,6 @@ module OmniAuth module MapsMe - VERSION = "1.0.3" + VERSION = "1.0.4" end module MapsMeToken diff --git a/lib/omniauth/strategies/mapsme-base.rb b/lib/omniauth/strategies/mapsme-base.rb index 29b06fd..5dd76c3 100644 --- a/lib/omniauth/strategies/mapsme-base.rb +++ b/lib/omniauth/strategies/mapsme-base.rb @@ -2,12 +2,30 @@ module OmniAuth module Strategies module MapsMeBase MAPSME_BASE = 'https://passport.maps.me' + MAPSME_DEFAULT_SCOPE = 'read' + MAPSME_USER_DETAILS = '/user_details/' MAPSME_CLIENT_OPTIONS = { :site => MAPSME_BASE, :authorize_url => "#{MAPSME_BASE}/oauth/authorize", - :token_url => "#{MAPSME_BASE}/oauth/token" + :token_url => "#{MAPSME_BASE}/oauth/token/" } + + def extract_name(raw_info) + first_name = raw_info['first_name'] + last_name = raw_info['last_name'] + username = raw_info['username'] + + if first_name + if last_name + "#{first_name} #{last_name}" + else + first_name + end + else + username + end + end end end end diff --git a/lib/omniauth/strategies/mapsme-token.rb b/lib/omniauth/strategies/mapsme-token.rb index 64fd92f..2866172 100644 --- a/lib/omniauth/strategies/mapsme-token.rb +++ b/lib/omniauth/strategies/mapsme-token.rb @@ -24,12 +24,12 @@ module OmniAuth attr_accessor :access_token - uid { raw_info['uid'].to_s } + uid { raw_info['username'] } info do prune!({ 'email' => raw_info['email'], - 'name' => raw_info['name'] + 'name' => extract_name(raw_info) }) end @@ -47,12 +47,12 @@ module OmniAuth def authorize_params super.tap do |params| - params[:scope] = 'user mail' + params[:scope] = MAPSME_DEFAULT_SCOPE end end def raw_info - @raw_info ||= access_token.get('/user').parsed || {} + @raw_info ||= access_token.get(MAPSME_USER_DETAILS).parsed || {} end def info_options diff --git a/lib/omniauth/strategies/mapsme.rb b/lib/omniauth/strategies/mapsme.rb index 85705df..31a5bee 100644 --- a/lib/omniauth/strategies/mapsme.rb +++ b/lib/omniauth/strategies/mapsme.rb @@ -10,12 +10,12 @@ module OmniAuth option :client_options, MAPSME_CLIENT_OPTIONS - uid { raw_info['uid'].to_s } + uid { raw_info['username'] } info do { 'email' => raw_info['email'], - 'name' => raw_info['name'] + 'name' => extract_name(raw_info) } end @@ -25,12 +25,12 @@ module OmniAuth def authorize_params super.tap do |params| - params[:scope] = 'user mail' + params[:scope] = MAPSME_DEFAULT_SCOPE end end def raw_info - @raw_info ||= access_token.get('/user').parsed || {} + @raw_info ||= access_token.get(MAPSME_USER_DETAILS).parsed || {} end # Fix omniauth-oauth2 issue https://github.com/intridea/omniauth-oauth2/issues/76