Skip to content

Commit c700cd7

Browse files
fix test cases
1 parent 2822c82 commit c700cd7

3 files changed

Lines changed: 30 additions & 15 deletions

File tree

auth0_flutter/EXAMPLES.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,10 @@ final didStore =
703703
704704
### Custom Token Exchange
705705

706-
[Custom Token Exchange](https://auth0.com/docs/authenticate/custom-token-exchange) allows you to exchange tokens from external identity providers for Auth0 tokens. This is useful for migrating users from legacy systems or integrating with third-party identity providers.
706+
[Custom Token Exchange](https://auth0.com/docs/authenticate/custom-token-exchange) allows you to enable applications to exchange their existing tokens for Auth0 tokens when calling the /oauth/token endpoint. This is useful for advanced integration use cases, such as:
707+
- Get Auth0 tokens for another audience
708+
- Integrate an external identity provider
709+
- Migrate to Auth0
707710

708711
> **Note:** This feature is currently available in [Early Access](https://auth0.com/docs/troubleshoot/product-lifecycle/product-release-stages#early-access). Please reach out to Auth0 support to enable it for your tenant.
709712
@@ -739,11 +742,6 @@ final credentials = await auth0Web.customTokenExchange(
739742

740743
</details>
741744

742-
**Required setup:**
743-
1. Configure a Custom Token Exchange profile in your Auth0 Dashboard
744-
2. Implement validation logic in an Auth0 Action to verify the external token
745-
3. Grant your Auth0 application the `urn:auth0:oauth2:grant-type:token-exchange` permission
746-
747745
> 💡 For more information, see the [Custom Token Exchange documentation](https://auth0.com/docs/authenticate/custom-token-exchange) and [RFC 8693](https://tools.ietf.org/html/rfc8693).
748746
749747
### Errors

auth0_flutter/test/web/auth0_flutter_web_test.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ void main() {
416416
group('customTokenExchange', () {
417417
test('customTokenExchange is called with required parameters and succeeds',
418418
() async {
419-
when(mockClientProxy.exchangeToken(argThat(anything)))
419+
when(mockClientProxy.exchangeToken(any))
420420
.thenAnswer((final _) => Future.value(webCredentials));
421421

422422
final result = await auth0.customTokenExchange(
@@ -440,7 +440,7 @@ void main() {
440440

441441
test('customTokenExchange is called with all optional parameters',
442442
() async {
443-
when(mockClientProxy.exchangeToken(argThat(anything)))
443+
when(mockClientProxy.exchangeToken(any))
444444
.thenAnswer((final _) => Future.value(webCredentials));
445445

446446
await auth0.customTokenExchange(
@@ -460,7 +460,7 @@ void main() {
460460
});
461461

462462
test('customTokenExchange is called with custom parameters', () async {
463-
when(mockClientProxy.exchangeToken(argThat(anything)))
463+
when(mockClientProxy.exchangeToken(any))
464464
.thenAnswer((final _) => Future.value(webCredentials));
465465

466466
await auth0.customTokenExchange(
@@ -479,7 +479,7 @@ void main() {
479479
});
480480

481481
test('customTokenExchange handles empty scopes correctly', () async {
482-
when(mockClientProxy.exchangeToken(argThat(anything)))
482+
when(mockClientProxy.exchangeToken(any))
483483
.thenAnswer((final _) => Future.value(webCredentials));
484484

485485
await auth0.customTokenExchange(
@@ -493,7 +493,7 @@ void main() {
493493
});
494494

495495
test('customTokenExchange throws WebException on error', () async {
496-
when(mockClientProxy.exchangeToken(argThat(anything)))
496+
when(mockClientProxy.exchangeToken(any))
497497
.thenThrow(createJsException('invalid_token', 'Token is invalid'));
498498

499499
expect(
@@ -515,7 +515,7 @@ void main() {
515515
];
516516

517517
for (final errorCase in errorCases) {
518-
when(mockClientProxy.exchangeToken(argThat(anything)))
518+
when(mockClientProxy.exchangeToken(any))
519519
.thenThrow(createJsException(errorCase['code']!, errorCase['message']!));
520520

521521
expect(
@@ -539,7 +539,7 @@ void main() {
539539
scope: 'openid profile email read:data write:data',
540540
expires_in: 0.toJS);
541541

542-
when(mockClientProxy.exchangeToken(argThat(anything)))
542+
when(mockClientProxy.exchangeToken(any))
543543
.thenAnswer((final _) => Future.value(customScopeCredentials));
544544

545545
final result = await auth0.customTokenExchange(
@@ -558,7 +558,7 @@ void main() {
558558
scope: 'openid',
559559
expires_in: 0.toJS);
560560

561-
when(mockClientProxy.exchangeToken(argThat(anything)))
561+
when(mockClientProxy.exchangeToken(any))
562562
.thenAnswer((final _) => Future.value(credentialsNoRefresh));
563563

564564
final result = await auth0.customTokenExchange(
@@ -571,7 +571,7 @@ void main() {
571571

572572
test('customTokenExchange converts JS credentials to Dart Credentials',
573573
() async {
574-
when(mockClientProxy.exchangeToken(argThat(anything)))
574+
when(mockClientProxy.exchangeToken(any))
575575
.thenAnswer((final _) => Future.value(webCredentials));
576576

577577
final result = await auth0.customTokenExchange(

auth0_flutter/test/web/auth0_flutter_web_test.mocks.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,23 @@ class MockAuth0FlutterWebClientProxy extends _i1.Mock
135135
)) as _i2.WebCredentials),
136136
) as _i4.Future<_i2.WebCredentials>);
137137

138+
@override
139+
_i4.Future<_i2.WebCredentials> exchangeToken(_i2.ExchangeTokenOptions? options) =>
140+
(super.noSuchMethod(
141+
Invocation.method(
142+
#exchangeToken,
143+
[options],
144+
),
145+
returnValue: _i4.Future<_i2.WebCredentials>.value(
146+
createJSInteropWrapper<_FakeWebCredentials_1>(_FakeWebCredentials_1(
147+
this,
148+
Invocation.method(
149+
#exchangeToken,
150+
[options],
151+
),
152+
)) as _i2.WebCredentials),
153+
) as _i4.Future<_i2.WebCredentials>);
154+
138155
@override
139156
_i4.Future<_i2.RedirectLoginResult> handleRedirectCallback([String? url]) =>
140157
(super.noSuchMethod(

0 commit comments

Comments
 (0)