Skip to content
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

Add Device Authorization Grant #30

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ColinFrick
Copy link
Collaborator

Adds the Device Authorization Grant.

Current workflow:

  1. Use deviceAuthorize() to start the Device Authorization Flow
  2. Display verification link and user code, or QR code with full verification link in the app
  3. Call getDeviceFusionAuthState(), this starts a Flow that polls the back end until the user has logged-in using the verification link and user code, or the link has expired
  4. Finally, verify logged in status and navigate to Activity

Things that are not yet implemented

  • Make flow / polling cancellable
  • Improve retry mechanism

Because this is not covered by AppAuth implementation, I've marked it with an ExperimentalApi decorator.

Related PR on AppAuth openid/AppAuth-Android#763

@ColinFrick ColinFrick added the enhancement New feature or request label Feb 22, 2024
@MainThread
private fun displayLoading(loadingMessage: String) {
findViewById<View>(R.id.loading_container).visibility = View.VISIBLE
findViewById<View>(R.id.auth_container).visibility = View.GONE

Check failure

Code scanning / mobsfscan

Hidden elements in view can be used to hide data from user. But this data can be leaked. Error

Hidden elements in view can be used to hide data from user. But this data can be leaked.
// Is logged in!
startActivity(Intent(this@DeviceLoginActivity, TokenActivity::class.java))
} catch (e: AuthorizationException) {
Log.e(DeviceLoginActivity.TAG, "Error while authorizing", e)

Check notice

Code scanning / mobsfscan

The App logs information. Sensitive information should never be logged. Note

The App logs information. Sensitive information should never be logged.

displayLoading("Polling for authorization")

val authState = AuthorizationManager

Check warning

Code scanning / detekt

Property is unused and should be removed. Warning

Private property authState is unused.
* @return The FusionAuthState object that contains the access token, access token expiration time, and id token.
*/
@OptIn(ExperimentalSerializationApi::class)
private suspend fun deviceAuthorizePolling(response: OAuthDeviceAuthorizationResponse): Flow<FusionAuthState> {

Check warning

Code scanning / detekt

The `suspend` modifier should not be used for functions that return a Coroutines Flow type. Flows are cold streams and invoking a function that returns one should not produce any side effects. Warning

suspend function returns Coroutines Flow.
Comment on lines +290 to +292
flow.catch {
continuation.resumeWithException(it)
}

Check warning

Code scanning / detekt

This call returns a value which is ignored Warning

The call catch is returning a value that is ignored.

displayLoading("Polling for authorization")

val authState = AuthorizationManager

Check notice

Code scanning / CodeQL

Unread local variable Note

Variable 'FusionAuthState authState' is never read.
@mooreds
Copy link
Contributor

mooreds commented Feb 22, 2024

Hiya, I'd rather focus on getting this SDK shipped with equivalent functionality to AppAuth and not moving forward with new features. We still have the iOS SDK to implement as well. Then we can come back and discuss new features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants