Skip to content

Commit 1a8b598

Browse files
committed
feat: dynamic microsoft graph/yammer profile endpoint to fix invalid audience for yammer
1 parent 93575a3 commit 1a8b598

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

lib/omniauth/strategies/microsoft_graph.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class MicrosoftGraph < OmniAuth::Strategies::OAuth2
66
BASE_SCOPE_URL = 'https://graph.microsoft.com/'
77
BASE_SCOPES = %w[offline_access openid email profile].freeze
88
DEFAULT_SCOPE = 'offline_access openid email profile User.Read'.freeze
9+
YAMMER_PROFILE_URL = 'https://www.yammer.com/api/v1/users/current.json'
10+
MICROSOFT_GRAPH_PROFILE_URL = 'https://graph.microsoft.com/v1.0/me'
911

1012
option :name, :microsoft_graph
1113

@@ -64,7 +66,7 @@ def authorize_params
6466
end
6567

6668
def raw_info
67-
@raw_info ||= access_token.get('https://graph.microsoft.com/v1.0/me').parsed
69+
@raw_info ||= access_token.get(profile_endpoint).parsed
6870
end
6971

7072
def callback_url
@@ -73,11 +75,25 @@ def callback_url
7375

7476
def custom_build_access_token
7577
access_token = get_access_token(request)
78+
# Get the profile(microsoft graph / yammer) endpoint choice based on returned bearer token
79+
@profile_endpoint = determine_profile_endpoint(request)
7680
access_token
7781
end
7882

7983
alias build_access_token custom_build_access_token
8084

85+
def profile_endpoint
86+
@profile_endpoint ||= MICROSOFT_GRAPH_PROFILE_URL
87+
end
88+
89+
def determine_profile_endpoint(request)
90+
if request.env['omniauth.params']['scope']&.include? 'yammer'
91+
YAMMER_PROFILE_URL
92+
else
93+
MICROSOFT_GRAPH_PROFILE_URL
94+
end
95+
end
96+
8197
private
8298

8399
def get_access_token(request)

0 commit comments

Comments
 (0)