Skip to content

Commit dcf2174

Browse files
authored
Merge pull request #3 from identification-io/master
Upgrade to v2.0 OAuth endpoint
2 parents 6e9f785 + c2ad730 commit dcf2174

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Omniauth
2-
module Office365
3-
VERSION = "0.1.0"
2+
module MicrosoftGraph
3+
VERSION = "0.1.1"
44
end
55
end

lib/omniauth/strategies/microsoft_graph.rb

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,22 @@ class MicrosoftGraph < OmniAuth::Strategies::OAuth2
66
option :name, :microsoft_graph
77

88
option :client_options, {
9-
site: 'https://login.microsoftonline.com/common/oauth2/authorize',
10-
token_url: 'https://login.microsoftonline.com/common/oauth2/token',
11-
authorize_url: 'https://login.microsoftonline.com/common/oauth2/authorize'
9+
site: 'https://login.microsoftonline.com',
10+
token_url: '/common/oauth2/v2.0/token',
11+
authorize_url: '/common/oauth2/v2.0/authorize'
1212
}
1313

14-
option :authorize_params, {
15-
resource: 'https://graph.microsoft.com/'
16-
}
17-
18-
option :token_params, {
19-
resource: 'https://graph.microsoft.com/'
20-
}
14+
option :authorize_options, %i[display score auth_type scope prompt login_hint domain_hint response_mode]
2115

2216
uid { raw_info["id"] }
2317

2418
info do
2519
{
26-
'email' => raw_info["mail"],
27-
'first_name' => raw_info["givenName"],
28-
'last_name' => raw_info["surname"],
29-
'name' => [raw_info["givenName"], raw_info["surname"]].join(' '),
30-
'nickname' => raw_info["displayName"],
20+
email: raw_info["mail"] || raw_info["userPrincipalName"],
21+
first_name: raw_info["givenName"],
22+
last_name: raw_info["surname"],
23+
name: full_name,
24+
nickname: raw_info["userPrincipalName"],
3125
}
3226
end
3327

@@ -39,7 +33,21 @@ class MicrosoftGraph < OmniAuth::Strategies::OAuth2
3933
end
4034

4135
def raw_info
42-
@raw_info ||= access_token.get(authorize_params.resource + 'v1.0/me').parsed
36+
@raw_info ||= access_token.get('https://graph.microsoft.com/v1.0/me').parsed
37+
end
38+
39+
def authorize_params
40+
super.tap do |params|
41+
%w[display score auth_type].each do |v|
42+
if request.params[v]
43+
params[v.to_sym] = request.params[v]
44+
end
45+
end
46+
end
47+
end
48+
49+
def full_name
50+
raw_info.values_at("givenName", "surname").compact.join(' ')
4351
end
4452
end
4553
end

omniauth-microsoft_graph.gemspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ require 'omniauth/microsoft_graph/version'
55

66
Gem::Specification.new do |spec|
77
spec.name = "omniauth-microsoft_graph"
8-
spec.version = Omniauth::Office365::VERSION
9-
spec.authors = ["Peter Philips"]
10-
spec.email = ["pete@p373.net"]
8+
spec.version = Omniauth::MicrosoftGraph::VERSION
9+
spec.authors = ["Peter Philips", "Joel Van Horn"]
10+
spec.email = ["pete@p373.net", "joel@joelvanhorn.com"]
1111
spec.summary = %q{omniauth provider for Microsoft Graph}
1212
spec.description = %q{omniauth provider for new Microsoft Graph API}
1313
spec.homepage = "https://github.com/synth/omniauth-microsoft_graph"

0 commit comments

Comments
 (0)