Skip to content

Commit

Permalink
Add required name field. Fix avatar test.
Browse files Browse the repository at this point in the history
Add `name` field to omniauth response as described in
 [Omniauth Hash Schema](https://github.com/omniauth/omniauth/wiki/Auth-Hash-Schema).
  • Loading branch information
milan-cvetkovic committed Aug 7, 2023
1 parent a4284b1 commit 2221077
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/omniauth/strategies/microsoft_office365.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class MicrosoftOffice365 < OmniAuth::Strategies::OAuth2
info do
{
email: raw_info["mail"] || raw_info["userPrincipalName"],
name: raw_info["displayName"],
display_name: raw_info["displayName"],
first_name: raw_info["givenName"],
last_name: raw_info["surname"],
Expand Down
4 changes: 3 additions & 1 deletion spec/omniauth/strategies/microsoft_office365_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@

it "returns a hash containing normalized user data" do
expect(strategy.info).to match({
name: "Luke Skywalker",
display_name: "Luke Skywalker",
email: "[email protected]",
first_name: "Luke",
Expand All @@ -139,7 +140,7 @@
end

context "when user didn't provide avatar image" do
let(:avatar_response) { instance_double(OAuth2::Response, "error=" => nil, status: 404, parsed: {}, body: '') }
let(:avatar_response) { instance_double(OAuth2::Response, status: 404, parsed: {}, body: '') }

before do
expect(access_token).to receive(:get).with("https://graph.microsoft.com/v1.0/me/photo/$value")
Expand All @@ -148,6 +149,7 @@

it "returns a hash containing normalized user data" do
expect(strategy.info).to match({
name: "Luke Skywalker",
display_name: "Luke Skywalker",
email: "[email protected]",
first_name: "Luke",
Expand Down

0 comments on commit 2221077

Please sign in to comment.