omniauth-microsoft-office365 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f1593595f1128cc3961d2e8a41f7e5c7c8b527d
|
4
|
+
data.tar.gz: 148bd4e0ad5ca323afc732f8399a78823c6613fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae2328eee7df00e7d9b78a79c15f8820c35a091b2debf517e644059d21176b917d259b68bacd04c431068ae44da6d2a280aa9ef5089d9ea1afcdcf45dbc87a5a
|
7
|
+
data.tar.gz: e730a417f25b83aa3bf40af0533c1a78d564a3a81f638c9e5d55a7bb3bf2f81393fc01d46596a7f712f79a4db729fe1c23d6cf5ff919e847deaf85c07687c85d
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.3.
|
1
|
+
ruby-2.3.5
|
@@ -5,7 +5,7 @@ module OmniAuth
|
|
5
5
|
class MicrosoftOffice365 < OmniAuth::Strategies::OAuth2
|
6
6
|
option :name, :microsoft_office365
|
7
7
|
|
8
|
-
DEFAULT_SCOPE="openid
|
8
|
+
DEFAULT_SCOPE="openid User.Read Contacts.Read"
|
9
9
|
|
10
10
|
option :client_options, {
|
11
11
|
site: "https://login.microsoftonline.com",
|
@@ -13,18 +13,21 @@ module OmniAuth
|
|
13
13
|
token_url: "/common/oauth2/v2.0/token"
|
14
14
|
}
|
15
15
|
|
16
|
-
option :authorize_options, [
|
16
|
+
option :authorize_options, %w[scope domain_hint]
|
17
17
|
|
18
|
-
uid { raw_info["
|
18
|
+
uid { raw_info["id"] }
|
19
19
|
|
20
20
|
info do
|
21
21
|
{
|
22
|
-
email:
|
23
|
-
display_name:
|
24
|
-
first_name:
|
25
|
-
last_name:
|
26
|
-
|
27
|
-
|
22
|
+
email: raw_info["mail"] || raw_info["userPrincipalName"],
|
23
|
+
display_name: raw_info["displayName"],
|
24
|
+
first_name: raw_info["givenName"],
|
25
|
+
last_name: raw_info["surname"],
|
26
|
+
job_title: raw_info["jobTitle"],
|
27
|
+
business_phones: raw_info["businessPhones"],
|
28
|
+
mobile_phone: raw_info["mobilePhone"],
|
29
|
+
office_phone: raw_info["officePhone"],
|
30
|
+
image: avatar_file,
|
28
31
|
}
|
29
32
|
end
|
30
33
|
|
@@ -35,12 +38,12 @@ module OmniAuth
|
|
35
38
|
end
|
36
39
|
|
37
40
|
def raw_info
|
38
|
-
@raw_info ||= access_token.get("https://
|
41
|
+
@raw_info ||= access_token.get("https://graph.microsoft.com/v1.0/me").parsed
|
39
42
|
end
|
40
43
|
|
41
44
|
def authorize_params
|
42
45
|
super.tap do |params|
|
43
|
-
%w[display scope auth_type].each do |v|
|
46
|
+
%w[display domain_hint scope auth_type].each do |v|
|
44
47
|
if request.params[v]
|
45
48
|
params[v.to_sym] = request.params[v]
|
46
49
|
end
|
@@ -52,21 +55,12 @@ module OmniAuth
|
|
52
55
|
|
53
56
|
private
|
54
57
|
|
55
|
-
def first_last_from_display_name(display_name)
|
56
|
-
# For display names with last name first like "Del Toro, Benicio"
|
57
|
-
if last_first = display_name.match(/^([^,]+),\s+(\S+)$/)
|
58
|
-
[last_first[2], last_first[1]]
|
59
|
-
else
|
60
|
-
display_name.split(/\s+/, 2)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
58
|
def callback_url
|
65
59
|
options[:redirect_uri] || (full_host + script_name + callback_path)
|
66
60
|
end
|
67
61
|
|
68
62
|
def avatar_file
|
69
|
-
photo = access_token.get("https://
|
63
|
+
photo = access_token.get("https://graph.microsoft.com/v1.0/me/photo/$value")
|
70
64
|
ext = photo.content_type.sub("image/", "") # "image/jpeg" => "jpeg"
|
71
65
|
|
72
66
|
Tempfile.new(["avatar", ".#{ext}"]).tap do |file|
|
@@ -78,7 +78,7 @@ RSpec.describe OmniAuth::Strategies::MicrosoftOffice365 do
|
|
78
78
|
|
79
79
|
it "uses correct scope and allows to customize authorization parameters" do
|
80
80
|
expect(strategy.authorize_params).to match(
|
81
|
-
"scope" => "openid
|
81
|
+
"scope" => "openid User.Read Contacts.Read",
|
82
82
|
"foo" => "bar",
|
83
83
|
"baz" => "zip",
|
84
84
|
"state" => /\A\h{48}\z/
|
@@ -89,18 +89,22 @@ RSpec.describe OmniAuth::Strategies::MicrosoftOffice365 do
|
|
89
89
|
describe "#info" do
|
90
90
|
let(:profile_response) do
|
91
91
|
instance_double(OAuth2::Response, parsed: {
|
92
|
-
"@odata.context"
|
93
|
-
"@odata.id"
|
94
|
-
"
|
95
|
-
"
|
96
|
-
"
|
97
|
-
"
|
98
|
-
"
|
92
|
+
"@odata.context" => "https://outlook.office.com/api/v2.0/$metadata#Me",
|
93
|
+
"@odata.id" => "https://outlook.office.com/api/v2.0/Users('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX@XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX')",
|
94
|
+
"id" => "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX@XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
|
95
|
+
"mail" => "luke.skywalker@example.com",
|
96
|
+
"displayName" => "Luke Skywalker",
|
97
|
+
"givenName" => "Luke",
|
98
|
+
"surname" => "Skywalker",
|
99
|
+
"jobTitle" => "Jedi Master",
|
100
|
+
"businessPhones" => ['555-555-5555'],
|
101
|
+
"mobilePhone" => '555-555-5556',
|
102
|
+
"MailboxGuid" => "YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY"
|
99
103
|
})
|
100
104
|
end
|
101
105
|
|
102
106
|
before do
|
103
|
-
expect(access_token).to receive(:get).with("https://
|
107
|
+
expect(access_token).to receive(:get).with("https://graph.microsoft.com/v1.0/me")
|
104
108
|
.and_return(profile_response)
|
105
109
|
end
|
106
110
|
|
@@ -108,17 +112,20 @@ RSpec.describe OmniAuth::Strategies::MicrosoftOffice365 do
|
|
108
112
|
let(:avatar_response) { instance_double(OAuth2::Response, content_type: "image/jpeg", body: "JPEG_STREAM") }
|
109
113
|
|
110
114
|
before do
|
111
|
-
expect(access_token).to receive(:get).with("https://
|
115
|
+
expect(access_token).to receive(:get).with("https://graph.microsoft.com/v1.0/me/photo/$value")
|
112
116
|
.and_return(avatar_response)
|
113
117
|
end
|
114
118
|
|
115
119
|
it "returns a hash containing normalized user data" do
|
116
120
|
expect(strategy.info).to match({
|
117
|
-
|
118
|
-
display_name: "Skywalker, Luke",
|
121
|
+
display_name: "Luke Skywalker",
|
119
122
|
email: "luke.skywalker@example.com",
|
120
123
|
first_name: "Luke",
|
121
124
|
last_name: "Skywalker",
|
125
|
+
job_title: "Jedi Master",
|
126
|
+
business_phones: ['555-555-5555'],
|
127
|
+
mobile_phone: '555-555-5556',
|
128
|
+
office_phone: nil,
|
122
129
|
image: Tempfile,
|
123
130
|
})
|
124
131
|
end
|
@@ -131,53 +138,24 @@ RSpec.describe OmniAuth::Strategies::MicrosoftOffice365 do
|
|
131
138
|
end
|
132
139
|
end
|
133
140
|
|
134
|
-
context "when the name is in alternate format" do
|
135
|
-
let(:avatar_response) { instance_double(OAuth2::Response, content_type: "image/jpeg", body: "JPEG_STREAM") }
|
136
|
-
|
137
|
-
before do
|
138
|
-
expect(access_token).to receive(:get).with("https://outlook.office.com/api/v2.0/me/photo/$value")
|
139
|
-
.and_return(avatar_response)
|
140
|
-
end
|
141
|
-
|
142
|
-
let(:profile_response) do
|
143
|
-
instance_double(OAuth2::Response, parsed: {
|
144
|
-
"@odata.context" => "https://outlook.office.com/api/v2.0/$metadata#Me",
|
145
|
-
"@odata.id" => "https://outlook.office.com/api/v2.0/Users('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX@XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX')",
|
146
|
-
"Id" => "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX@XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
|
147
|
-
"EmailAddress" => "luke.skywalker@example.com",
|
148
|
-
"DisplayName" => "Luke Skywalker",
|
149
|
-
"Alias" => "luke.skywalker",
|
150
|
-
"MailboxGuid" => "YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY"
|
151
|
-
})
|
152
|
-
end
|
153
|
-
|
154
|
-
it "returns the parsed first and last name correctly" do
|
155
|
-
expect(strategy.info).to match({
|
156
|
-
alias: "luke.skywalker",
|
157
|
-
display_name: "Luke Skywalker",
|
158
|
-
email: "luke.skywalker@example.com",
|
159
|
-
first_name: "Luke",
|
160
|
-
last_name: "Skywalker",
|
161
|
-
image: Tempfile,
|
162
|
-
})
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
141
|
context "when user didn't provide avatar image" do
|
167
142
|
let(:avatar_response) { instance_double(OAuth2::Response, "error=" => nil, status: 404, parsed: {}, body: '') }
|
168
143
|
|
169
144
|
before do
|
170
|
-
expect(access_token).to receive(:get).with("https://
|
145
|
+
expect(access_token).to receive(:get).with("https://graph.microsoft.com/v1.0/me/photo/$value")
|
171
146
|
.and_raise(OAuth2::Error, avatar_response)
|
172
147
|
end
|
173
148
|
|
174
149
|
it "returns a hash containing normalized user data" do
|
175
150
|
expect(strategy.info).to match({
|
176
|
-
|
177
|
-
display_name: "Skywalker, Luke",
|
151
|
+
display_name: "Luke Skywalker",
|
178
152
|
email: "luke.skywalker@example.com",
|
179
153
|
first_name: "Luke",
|
180
154
|
last_name: "Skywalker",
|
155
|
+
job_title: "Jedi Master",
|
156
|
+
business_phones: ['555-555-5555'],
|
157
|
+
mobile_phone: '555-555-5556',
|
158
|
+
office_phone: nil,
|
181
159
|
image: nil,
|
182
160
|
})
|
183
161
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-microsoft-office365
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcin Urbański
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth
|
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
version: '0'
|
137
137
|
requirements: []
|
138
138
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.5.
|
139
|
+
rubygems_version: 2.5.2.1
|
140
140
|
signing_key:
|
141
141
|
specification_version: 4
|
142
142
|
summary: OmniAuth provider for Microsoft Office365
|