Skip to content

Conversation

tusharpandey13
Copy link
Contributor

@tusharpandey13 tusharpandey13 commented Feb 28, 2025

Add tokenForConnection method to OAuth

Description

This PR adds a new tokenForConnection method to the OAuth class that allows exchanging a refresh token for a federated connection access token. This is particularly useful when you need to access a social provider's API using the user's refresh token.

This PR also removes enforcing namespace ownership requirements for token types in custom token exchange (this is not required to be done on SDK side)

References

Changes

  • Added TokenForConnectionOptions interface with required refreshToken and connection parameters, and optional loginHint
  • Added constants for grant type, token types, and endpoint URL
  • Implemented tokenForConnection method with proper parameter validation and error handling
  • Added comprehensive test suite covering success and error scenarios
  • Removed logic to enforce namespace ownership requirements for token types from customTokenExchange

Manual Testing Steps

  1. Initialize the OAuth client with your Auth0 credentials:
const oauth = new OAuth({
  domain: 'your-domain.auth0.com',
  clientId: 'your-client-id',
  clientSecret: 'your-client-secret'
});
  1. Call tokenForConnection method:
const response = await oauth.tokenForConnection({
  refreshToken: 'valid-refresh-token',
  connection: 'google-oauth2'
});
console.log(response.data.access_token);

Test Results

PASSING

Test Suites: 48 passed, 48 total
Tests:       1569 passed, 1569 total
Snapshots:   0 total
Time:        6.928 s, estimated 7 s
Ran all test suites.

@tusharpandey13 tusharpandey13 requested a review from a team as a code owner February 28, 2025 12:20
@tusharpandey13 tusharpandey13 changed the title feature/fcat Add tokenForConnection method to OAuth Mar 28, 2025
tanya732
tanya732 previously approved these changes Mar 28, 2025
update implementation to match current node auth0 methods
tanya732
tanya732 previously approved these changes Mar 28, 2025
Co-authored-by: Frederik Prijck <frederik.prijck@auth0.com>
@tusharpandey13 tusharpandey13 dismissed frederikprijck’s stale review March 28, 2025 17:28

these changes have been incorporated

@tusharpandey13 tusharpandey13 merged commit 8c17346 into master Mar 28, 2025
8 checks passed
@tusharpandey13 tusharpandey13 deleted the feature/fcat branch March 28, 2025 17:28
@tusharpandey13 tusharpandey13 mentioned this pull request Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants