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.
This PR adds some wrapper methods that allow callers to write idiomatic Kotlin code when using this library.
Examples of the usage differences are highlighted below.
Creating a
PublicClientApplication
can become a suspending function
The same thing applies to
createMultipleAccountPublicClientApplication
.[Single Account] Signing in
Usage of builders is not as common in Kotlin unless they need to perform complex operations. In this case, the builder for
SignInParameters
merely sets values, so we can just usesignIn
directly with named parameters while still keeping the proper defaults for the other unspecified ones.Furthermore, this can also become a suspending function
In this scenario,
authResult
would benull
in theonCancel
case.I think this is a reasonable default for a lot of applications, however, when user cancellation needs to be handled explicitly, developers can still opt to use the callback.
[Single Account] Signing out
can become a suspending function
[Single Account] Get signed-in account
can become a suspending function
In this scenario,
onAccountChanged
is ignored, but again, if an application needs to handle that in a special way, it can still use the callback.[Multiple Account] Get signed-in accounts
can become a suspending function
[Multiple Account] Remove account
can become a suspending function
Acquire a token
can become a suspending function
We can also get rid of the builder here as well.
The only builder method that has multiple overloads is
fromAuthority
, which we can replace by having a separateAuthority
class with multiple constructors.The same thing applies to
acquireTokenSilent
.Throughout these examples I've added
scope.launch
and error handling for completeness, but in practice the difference is even more noticeable because often these functions will be called from another suspend function so you don't need to launch a new coroutine scope, or you may be handling errors at a higher level so you don't need to handle every one separately.