-
Notifications
You must be signed in to change notification settings - Fork 57
CredentialsManager user info/ID token contents accessible via flutter SDK #607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
002b8d6
SDK-6070 flutter changes
NandanPrabhu ec84b59
method channel for accessing user info
NandanPrabhu 972008a
Merge branch 'main' into SDK-6070
NandanPrabhu e4acf09
build(deps): bump ruby/setup-ruby from 1.273.0 to 1.274.0 in /.github…
dependabot[bot] bf858a5
build(deps): bump ruby/setup-ruby from 1.274.0 to 1.275.0 in /.github…
dependabot[bot] 1970f42
build(deps): bump ruby/setup-ruby from 1.275.0 to 1.278.0 in /.github…
dependabot[bot] e7c7db6
build(deps): bump ruby/setup-ruby from 1.278.0 to 1.279.0 in /.github…
dependabot[bot] d2db273
build(deps): bump ruby/setup-ruby from 1.279.0 to 1.281.0 in /.github…
dependabot[bot] 8238bfd
build(deps): bump ruby/setup-ruby in /.github/actions/setup-darwin
dependabot[bot] ae53ba3
build(deps): bump ruby/setup-ruby from 1.282.0 to 1.283.0 in /.github…
dependabot[bot] 7385394
build(deps): bump ruby/setup-ruby from 1.283.0 to 1.285.0 in /.github…
dependabot[bot] 5a97d0a
feat: Add allowedBrowsers parameter to logout API [SDK-724] (#726)
pmathew92 7df2b95
feat: add custom token exchange support across all platforms
sanchitmehtagit 1051510
fixed test cases
sanchitmehtagit 6fcec69
fixed test cases
sanchitmehtagit a967065
fix test cases and code refactoring
sanchitmehtagit 2997dc4
refactor
sanchitmehtagit 0fa36df
address feedback
sanchitmehtagit ae788f7
chore:Fixed errors from flutter analyze (#727)
pmathew92 e81599b
build(deps-dev): bump lodash from 4.17.21 to 4.17.23 in /appium-test …
dependabot[bot] 721d875
build(deps): bump ruby/setup-ruby from 1.285.0 to 1.286.0 in /.github…
dependabot[bot] d2ea484
fix flutter analyse errors
sanchitmehtagit 616f589
pubspec update for beta release
sanchitmehtagit 89467e8
Release afpi-v2.0.0-beta.2
sanchitmehtagit f688cd4
Release af-v2.0.0-beta.2
sanchitmehtagit 7afabd8
udpate podspecs
sanchitmehtagit e5cf989
udpate pubspec
sanchitmehtagit fd9e914
make PR runs with release workflow that triggers flutter analyze
sanchitmehtagit 27f7ad7
Avoid running always failing smoke tests for iOS
sanchitmehtagit 9186451
CI cleanup
sanchitmehtagit e654edc
Resolved merge conflict
pmathew92 ebd57d9
Renamed getIDTokenContents to user
pmathew92 1d5246d
Added the code to get profile from android SDK
pmathew92 2424bf9
Added changes to darwin and other classes
pmathew92 e39ff33
Added test cases for the user API
pmathew92 932925c
fixed analyze error
pmathew92 d825b01
name change in the method handler class
pmathew92 f43cd21
Fixed the failing test cases
pmathew92 69688d4
Merge branch 'main' into SDK-6070
pmathew92 d70d1e1
Fixed the error in analyze due to the branch conflict issue
pmathew92 ad06a37
fixing swift failures on UTs
pmathew92 a9cd6ac
Updated the workflow file
pmathew92 d80cfa8
Minor change
pmathew92 f6f2bf5
Minor changes from review comments
pmathew92 c34c152
reverting changes in the Mocks.swift file
pmathew92 7fde8c3
Reverting the MacOs delegate runner
pmathew92 3174ce9
updated xcode version to 26.2
pmathew92 bef9ef2
Removed unwanted code
pmathew92 b14bb8b
Updated Examples.md file
pmathew92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...uth0_flutter/request_handlers/credentials_manager/GetCredentialsUserInfoRequestHandler.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.auth0.auth0_flutter.request_handlers.credentials_manager | ||
|
|
||
| import android.content.Context | ||
| import com.auth0.android.authentication.storage.SecureCredentialsManager | ||
| import com.auth0.auth0_flutter.request_handlers.MethodCallRequest | ||
| import com.auth0.auth0_flutter.toMap | ||
| import io.flutter.plugin.common.MethodChannel | ||
|
|
||
|
|
||
| class GetCredentialsUserInfoRequestHandler: CredentialsManagerRequestHandler { | ||
| override val method: String = "credentialsManager#user" | ||
| override fun handle( | ||
| credentialsManager: SecureCredentialsManager, | ||
| context: Context, | ||
| request: MethodCallRequest, | ||
| result: MethodChannel.Result | ||
| ) { | ||
| val userProfile = credentialsManager.userProfile | ||
| if (userProfile != null) { | ||
| result.success(userProfile.toMap()) | ||
| } else { | ||
| result.success(null) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import android.content.Context | |
| import android.content.SharedPreferences | ||
| import com.auth0.auth0_flutter.request_handlers.credentials_manager.ClearCredentialsRequestHandler | ||
| import com.auth0.auth0_flutter.request_handlers.credentials_manager.CredentialsManagerRequestHandler | ||
| import com.auth0.auth0_flutter.request_handlers.credentials_manager.GetCredentialsUserInfoRequestHandler | ||
| import com.auth0.auth0_flutter.request_handlers.credentials_manager.HasValidCredentialsRequestHandler | ||
| import io.flutter.plugin.common.MethodCall | ||
| import io.flutter.plugin.common.MethodChannel.Result | ||
|
|
@@ -41,7 +42,16 @@ class CredentialsManagerMethodCallHandlerTest { | |
| val mockResult = mock<Result>() | ||
|
|
||
| handler.activity = if (activity === null) mock() else activity | ||
| handler.context = if (context === null) mock() else context | ||
|
|
||
| val mockContext = if (context === null) { | ||
| val ctx: Context = mock() | ||
| val mockPrefs: SharedPreferences = mock() | ||
| `when`(ctx.getSharedPreferences(any(), any())).thenReturn(mockPrefs) | ||
| ctx | ||
| } else { | ||
| context | ||
| } | ||
| handler.context = mockContext | ||
|
|
||
| handler.onMethodCall(MethodCall(method, arguments), mockResult) | ||
| onResult(mockResult) | ||
|
|
@@ -139,7 +149,7 @@ class CredentialsManagerMethodCallHandlerTest { | |
|
|
||
| val managerCaptor = argumentCaptor<com.auth0.android.authentication.storage.SecureCredentialsManager>() | ||
| verify(clearCredentialsHandler, times(2)).handle(managerCaptor.capture(), any(), any(), any()) | ||
|
|
||
| MatcherAssert.assertThat( | ||
| "Manager should be reused when configuration is identical", | ||
| managerCaptor.firstValue, | ||
|
|
@@ -193,7 +203,7 @@ class CredentialsManagerMethodCallHandlerTest { | |
|
|
||
| val managerCaptor = argumentCaptor<com.auth0.android.authentication.storage.SecureCredentialsManager>() | ||
| verify(clearCredentialsHandler, times(2)).handle(managerCaptor.capture(), any(), any(), any()) | ||
|
|
||
| MatcherAssert.assertThat( | ||
| "New manager should be created when domain changes", | ||
| managerCaptor.firstValue, | ||
|
|
@@ -233,7 +243,7 @@ class CredentialsManagerMethodCallHandlerTest { | |
| val arguments2 = hashMapOf<String, Any?>( | ||
| "_account" to mapOf( | ||
| "domain" to "test.auth0.com", | ||
| "clientId" to "client-2", | ||
| "clientId" to "client-2", | ||
| ), | ||
| "_userAgent" to mapOf( | ||
| "name" to "auth0-flutter", | ||
|
|
@@ -245,7 +255,7 @@ class CredentialsManagerMethodCallHandlerTest { | |
|
|
||
| val managerCaptor = argumentCaptor<com.auth0.android.authentication.storage.SecureCredentialsManager>() | ||
| verify(clearCredentialsHandler, times(2)).handle(managerCaptor.capture(), any(), any(), any()) | ||
|
|
||
| MatcherAssert.assertThat( | ||
| "New manager should be created when clientId changes", | ||
| managerCaptor.firstValue, | ||
|
|
@@ -294,15 +304,15 @@ class CredentialsManagerMethodCallHandlerTest { | |
| "version" to "1.0.0" | ||
| ), | ||
| "credentialsManagerConfiguration" to mapOf( | ||
| "android" to mapOf("sharedPreferencesName" to "prefs_2") | ||
| "android" to mapOf("sharedPreferencesName" to "prefs_2") | ||
| ) | ||
| ) | ||
| val call2 = MethodCall("credentialsManager#clearCredentials", arguments2) | ||
| handler.onMethodCall(call2, mockResult) | ||
|
|
||
| val managerCaptor = argumentCaptor<com.auth0.android.authentication.storage.SecureCredentialsManager>() | ||
| verify(clearCredentialsHandler, times(2)).handle(managerCaptor.capture(), any(), any(), any()) | ||
|
|
||
| MatcherAssert.assertThat( | ||
| "New manager should be created when sharedPreferencesName changes", | ||
| managerCaptor.firstValue, | ||
|
|
@@ -349,14 +359,14 @@ class CredentialsManagerMethodCallHandlerTest { | |
| "name" to "auth0-flutter", | ||
| "version" to "1.0.0" | ||
| ), | ||
| "useDPoP" to true | ||
| "useDPoP" to true | ||
| ) | ||
| val call2 = MethodCall("credentialsManager#clearCredentials", arguments2) | ||
| handler.onMethodCall(call2, mockResult) | ||
|
|
||
| val managerCaptor = argumentCaptor<com.auth0.android.authentication.storage.SecureCredentialsManager>() | ||
| verify(clearCredentialsHandler, times(2)).handle(managerCaptor.capture(), any(), any(), any()) | ||
|
|
||
| MatcherAssert.assertThat( | ||
| "New manager should be created when useDPoP flag changes", | ||
| managerCaptor.firstValue, | ||
|
|
@@ -414,7 +424,7 @@ class CredentialsManagerMethodCallHandlerTest { | |
|
|
||
| val managerCaptor = argumentCaptor<com.auth0.android.authentication.storage.SecureCredentialsManager>() | ||
| verify(clearCredentialsHandler, times(2)).handle(managerCaptor.capture(), any(), any(), any()) | ||
|
|
||
| MatcherAssert.assertThat( | ||
| "New manager should be created when localAuthentication changes", | ||
| managerCaptor.firstValue, | ||
|
|
@@ -426,7 +436,7 @@ class CredentialsManagerMethodCallHandlerTest { | |
| fun `handler should reuse manager across different method calls with same configuration`() { | ||
| val clearCredentialsHandler = mock<ClearCredentialsRequestHandler>() | ||
| val hasValidCredentialsHandler = mock<HasValidCredentialsRequestHandler>() | ||
|
|
||
| `when`(clearCredentialsHandler.method).thenReturn("credentialsManager#clearCredentials") | ||
| `when`(hasValidCredentialsHandler.method).thenReturn("credentialsManager#hasValidCredentials") | ||
|
|
||
|
|
@@ -451,15 +461,58 @@ class CredentialsManagerMethodCallHandlerTest { | |
|
|
||
| val clearManagerCaptor = argumentCaptor<com.auth0.android.authentication.storage.SecureCredentialsManager>() | ||
| val hasValidManagerCaptor = argumentCaptor<com.auth0.android.authentication.storage.SecureCredentialsManager>() | ||
|
|
||
| verify(clearCredentialsHandler).handle(clearManagerCaptor.capture(), any(), any(), any()) | ||
| verify(hasValidCredentialsHandler).handle(hasValidManagerCaptor.capture(), any(), any(), any()) | ||
|
|
||
| MatcherAssert.assertThat( | ||
| "Same manager should be reused across different method calls with identical configuration", | ||
| clearManagerCaptor.firstValue, | ||
| CoreMatchers.sameInstance(hasValidManagerCaptor.firstValue) | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `handler invokes GetCredentialsUserInfoRequestHandler for credentialsManager#user`() { | ||
| val getUserInfoHandler = mock<GetCredentialsUserInfoRequestHandler>() | ||
| `when`(getUserInfoHandler.method).thenReturn("credentialsManager#user") | ||
|
|
||
| runCallHandler( | ||
| "credentialsManager#user", | ||
| requestHandlers = listOf(getUserInfoHandler) | ||
| ) { result -> | ||
| verify(getUserInfoHandler).handle(any(), any(), any(), any()) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun `handler returns UserProfile result from GetCredentialsUserInfoRequestHandler`() { | ||
| val getUserInfoHandler = mock<GetCredentialsUserInfoRequestHandler>() | ||
| `when`(getUserInfoHandler.method).thenReturn("credentialsManager#user") | ||
|
|
||
| val userProfileMap = mapOf( | ||
| "sub" to "auth0|123456", | ||
| "name" to "John Doe", | ||
| "email" to "[email protected]" | ||
| ) | ||
|
|
||
| doAnswer { invocation -> | ||
| val result = invocation.getArgument<Result>(3) | ||
| result.success(userProfileMap) | ||
| }.`when`(getUserInfoHandler).handle(any(), any(), any(), any()) | ||
|
|
||
| val mockResult = mock<Result>() | ||
| val handler = CredentialsManagerMethodCallHandler(listOf(getUserInfoHandler)) | ||
| handler.activity = mock() | ||
|
|
||
| val mockContext: Context = mock() | ||
| val mockPrefs: SharedPreferences = mock() | ||
| `when`(mockContext.getSharedPreferences(any(), any())).thenReturn(mockPrefs) | ||
| handler.context = mockContext | ||
|
|
||
| handler.onMethodCall(MethodCall("credentialsManager#user", defaultArguments), mockResult) | ||
|
|
||
| verify(mockResult).success(userProfileMap) | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we update the example doc please ignore if already done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have updated the Examples.md file