Skip to content

Commit d8d5c21

Browse files
committed
Do not include query params in callback URLs
In order to be compatible with GitHub Integration's Oauth flow the callback URL must match the same one provided in the integration's settings page. The current `callback_url` method includes any query params received previously, which causes a mismatch, and GitHub returns "406 Not Accepted" with an error message: ``` (github) Callback phase initiated. (github) Authentication failure! invalid_credentials: OAuth2::Error, redirect_uri_mismatch: The redirect_uri MUST match the registered callback URL for this application. error=redirect_uri_mismatch&error_description=The+redirect_uri+MUST+match+ the+registered+callback+URL+for+this+application.&error_uri=https%3A%2F%2 Fdeveloper.github.com%2Fv3%2Foauth%2F%23redirect-uri-mismatch2 ``` For more information: https://developer.github.com/early-access/integrations/user-identification-authorization
1 parent a893c2b commit d8d5c21

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/omniauth/strategies/github.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ def email_access_allowed?
6969
scopes = options['scope'].split(',')
7070
(scopes & email_scopes).any?
7171
end
72+
73+
def callback_url
74+
full_host + script_name + callback_path
75+
end
7276
end
7377
end
7478
end

spec/omniauth/strategies/github_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,13 @@
149149
expect(subject.info['urls']['GitHub']).to eq('http://enterprise/me')
150150
end
151151
end
152+
153+
describe '#callback_url' do
154+
it 'is a combination of host, script name, and callback path' do
155+
allow(subject).to receive(:full_host).and_return('https://example.com')
156+
allow(subject).to receive(:script_name).and_return('/sub_uri')
157+
158+
expect(subject.callback_url).to eq('https://example.com/sub_uri/auth/github/callback')
159+
end
160+
end
152161
end

0 commit comments

Comments
 (0)