fix(core): Fix OAuth1 callback token request (#14251)

This commit is contained in:
Elias Meire
2025-03-28 19:59:30 +01:00
committed by GitHub
parent 4443a5f532
commit 4ea219b1f7
2 changed files with 7 additions and 9 deletions

View File

@@ -230,15 +230,11 @@ describe('OAuth1CredentialController', () => {
}); });
jest.spyOn(Csrf.prototype, 'verify').mockReturnValueOnce(true); jest.spyOn(Csrf.prototype, 'verify').mockReturnValueOnce(true);
nock('https://example.domain') nock('https://example.domain')
.post('/oauth/access_token', { .post('/oauth/access_token', 'oauth_token=token&oauth_verifier=verifier')
oauth_token: 'token',
oauth_verifier: 'verifier',
})
.once() .once()
.reply(200, 'access_token=new_token'); .reply(200, 'access_token=new_token');
await controller.handleCallback(req, res); await controller.handleCallback(req, res);
const dataCaptor = captor(); const dataCaptor = captor();
expect(credentialsRepository.update).toHaveBeenCalledWith( expect(credentialsRepository.update).toHaveBeenCalledWith(
'1', '1',

View File

@@ -118,10 +118,12 @@ export class OAuth1CredentialController extends AbstractOAuthController {
const [credential, _, oauthCredentials] = const [credential, _, oauthCredentials] =
await this.resolveCredential<OAuth1CredentialData>(req); await this.resolveCredential<OAuth1CredentialData>(req);
const oauthToken = await axios.post<string>(oauthCredentials.accessTokenUrl, { // Form URL encoded body https://datatracker.ietf.org/doc/html/rfc5849#section-3.5.2
oauth_token, const oauthToken = await axios.post<string>(
oauth_verifier, oauthCredentials.accessTokenUrl,
}); { oauth_token, oauth_verifier },
{ headers: { 'content-type': 'application/x-www-form-urlencoded' } },
);
// Response comes as x-www-form-urlencoded string so convert it to JSON // Response comes as x-www-form-urlencoded string so convert it to JSON