-
Notifications
You must be signed in to change notification settings - Fork 61
feat: add My Account API support for managing MFA authentication method #835
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
Changes from all commits
f89de9e
f29c838
2e3e50c
efc7a35
8565baa
7722a35
be3ae58
d414191
d093d17
873179f
6299881
c97fe20
136d514
277f0c7
7a9a626
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.auth0.auth0_flutter | ||
|
|
||
| import android.content.Context | ||
| import androidx.annotation.NonNull | ||
| import com.auth0.android.myaccount.MyAccountAPIClient | ||
| import com.auth0.auth0_flutter.request_handlers.MethodCallRequest | ||
| import com.auth0.auth0_flutter.request_handlers.my_account.MyAccountRequestHandler | ||
| import com.auth0.auth0_flutter.utils.assertHasProperties | ||
| import io.flutter.plugin.common.MethodCall | ||
| import io.flutter.plugin.common.MethodChannel.MethodCallHandler | ||
| import io.flutter.plugin.common.MethodChannel.Result | ||
|
|
||
| class Auth0FlutterMyAccountMethodCallHandler( | ||
| private val myAccountRequestHandlers: List<MyAccountRequestHandler> | ||
| ) : MethodCallHandler { | ||
| lateinit var context: Context | ||
|
|
||
| override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) { | ||
| val request = MethodCallRequest.fromCall(call) | ||
|
|
||
| val handler = myAccountRequestHandlers.find { it.method == call.method } | ||
| if (handler != null) { | ||
| assertHasProperties(listOf("accessToken"), request.data) | ||
| val accessToken = request.data["accessToken"] as String | ||
| val useDPoP = request.data["useDPoP"] as? Boolean ?: false | ||
| val client = MyAccountAPIClient(request.account, accessToken).apply { | ||
| if (useDPoP) { | ||
| useDPoP(context) | ||
| } | ||
| } | ||
|
|
||
| handler.handle(client, request, result) | ||
| } else { | ||
| result.notImplemented() | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.auth0.auth0_flutter | ||
|
|
||
| import com.auth0.android.myaccount.MyAccountException | ||
|
|
||
| fun MyAccountException.toMyAccountMap(): Map<String, Any> { | ||
| val exception = this | ||
| return buildMap { | ||
| put("_statusCode", exception.statusCode) | ||
| put("_title", exception.getCode()) | ||
| put("_detail", exception.getDescription()) | ||
| put("_errorFlags", mapOf( | ||
| "isNetworkError" to exception.isNetworkError, | ||
| )) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. Added title and detail to the error map on both Android and iOS. Also exposed them as first-class properties on the Dart MyAccountException class (exception.title, exception.detail). |
||
| } | ||
| } | ||
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.
Are you able to authenticate with the
https://YOUR_DOMAIN/me/audience ? Ideally the recommended approach is use MRRT to get the token for my account audience and not get them while authenticating. check how RN has donehttps://github.com/auth0/react-native-auth0/blob/master/EXAMPLES.md#my-account-api
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.
Thanks, good point. The example authenticates against the me audience directly just to keep the sample minimal. I'll add a note to the README clarifying that the recommended production approach is to obtain a My Accountβaudience token via MRRT (Multi-Resource Refresh Token) rather than during the initial login, mirroring how react-native-auth0 documents it.
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.
@utkrishtsahu I don't see this note added. I owuld still recommend to follow the proper appraoch in the examples file