Skip to content

Commit 8a48ed6

Browse files
committed
merged oauth-v2 branch to become mainline
2 parents 2fe7824 + 624c953 commit 8a48ed6

File tree

1 file changed

+18
-34
lines changed

1 file changed

+18
-34
lines changed

lib/omniauth/strategies/microsoft_graph.rb

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

88
option :client_options, {
9-
site: 'https://login.microsoftonline.com',
10-
token_url: '/common/oauth2/v2.0/token',
11-
authorize_url: '/common/oauth2/v2.0/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_options, %i[display score auth_type scope prompt login_hint domain_hint response_mode]
14+
option :authorize_params, {
15+
}
16+
17+
option :token_params, {
18+
}
19+
20+
option :scope, "offline_access https://graph.microsoft.com/User.Read"
1521

1622
uid { raw_info["id"] }
1723

1824
info do
1925
{
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"],
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"],
2531
}
2632
end
2733

@@ -31,36 +37,14 @@ class MicrosoftGraph < OmniAuth::Strategies::OAuth2
3137
'params' => access_token.params
3238
}
3339
end
34-
35-
def callback_url
36-
options[:redirect_uri] || (full_host + script_name + callback_path)
37-
end
3840

3941
def raw_info
4042
@raw_info ||= access_token.get('https://graph.microsoft.com/v1.0/me').parsed
4143
end
4244

43-
def authorize_params
44-
super.tap do |params|
45-
%w[display score auth_type].each do |v|
46-
if request.params[v]
47-
params[v.to_sym] = request.params[v]
48-
end
49-
end
50-
end
51-
end
52-
53-
def full_name
54-
raw_info["displayName"].presence || raw_info.values_at("givenName", "surname").compact.join(' ')
55-
end
56-
57-
def build_access_token
58-
if request.params['access_token']
59-
::OAuth2::AccessToken.from_hash(client, request.params.dup)
60-
else
61-
super
62-
end
63-
end
45+
def callback_url
46+
options[:callback_url] || full_host + script_name + callback_path
47+
end
6448
end
6549
end
6650
end

0 commit comments

Comments
 (0)