Skip to content

Add new "Authorization" states and functions to authorize additional scopes. [ci full]#7306

Open
mhammond wants to merge 1 commit intomozilla:mainfrom
mhammond:push-mkxvwknxqksu
Open

Add new "Authorization" states and functions to authorize additional scopes. [ci full]#7306
mhammond wants to merge 1 commit intomozilla:mainfrom
mhammond:push-mkxvwknxqksu

Conversation

@mhammond
Copy link
Copy Markdown
Member

@mhammond mhammond commented Apr 7, 2026

As @jonalmeida and I were chatting about. @bendk does this look correct to you? @LZoog and @skhamis for some context for our slack messages.

This supports desktop-like flows, where a user is already signed in to (say) Sync, but not wants to authorize "vpn" or "smartwindow".

I used the term "Authorization" to try and reflect we aren't expected to "authenticate" here - we are already authenticated - we typically expect just a confirmation button. I'm not entirely convinced the distinction between "authorize" and "authenticate" is enough, so the names might be confusing - I started with something like "UpgradeScopes" etc. Regardless, better names welcome here.

I've tried to keep the names consistent, which made them verbose. Better names welcome here too.

Pull Request checklist

  • Breaking changes: This PR follows our breaking change policy
    • This PR follows the breaking change policy:
      • This PR has no breaking API changes, or
      • There are corresponding PRs for our consumer applications that resolve the breaking changes and have been approved
  • Quality: This PR builds and tests run cleanly
    • Note:
      • For changes that need extra cross-platform testing, consider adding [ci full] to the PR title.
      • If this pull request includes a breaking change, consider cutting a new release after merging.
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry in CHANGELOG.md or an explanation of why it does not need one
    • Any breaking changes to Swift or Kotlin binding APIs are noted explicitly
  • Dependencies: This PR follows our dependency management guidelines
    • Any new dependencies are accompanied by a summary of the due diligence applied in selecting them.

Copy link
Copy Markdown
Contributor

@bendk bendk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty much correct to me, except I think there's one more step to do.

My main takeaway is that these state machines feel overly complicated. It seems like you should be able to add an extra event, add code in a corresponding switch case, and that's it. When we were doing the Android migration and using the state machine tester to verify the code, we were getting some value in exchange. Now, more and more I'm feeling like we could rework this and simplify it.

FxaEvent::CheckAuthorizationStatus => Ok(CheckAuthorizationStatus),
FxaEvent::CallGetProfile => Ok(GetProfile),
FxaEvent::BeginOAuthScopeAuthorizationFlow { scopes, entrypoint } => {
Ok(BeginOAuthFlow { scopes, entrypoint })
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll need a new internal state for this since it should call begin_oauth_scope_authorization_flow() instead of begin_oauth_flow(). Ditto for the complete flow event.

state_machine/internal_machines/mod.rs should get some extra cases to map the new states to the right calls.

@mhammond mhammond force-pushed the push-mkxvwknxqksu branch 2 times, most recently from f2e57d0 to 735d3d7 Compare April 10, 2026 05:56
@mhammond
Copy link
Copy Markdown
Member Author

https://phabricator.services.mozilla.com/D293447 is the fenix side of this. I think I got the semantics correct for the new flow, but it's hard to know if it doesn't work for that reason or for an fxa reason - I know Lauren mentioned some work needs to be done on the fxa side for this to work. This PR however doesn't seem like a breaking change and should be safe even if it need tweaks - wdyt?

…scopes.

This supports desktop-like flows, where a user is already signed in to (say) Sync,
but not wants to authorize "vpn" or "smartwindow".

I used the term "Authorization" to try and reflect we aren't expected to "authenticate"
here - we are already authenticated - we typically expect just a confirmation button.
I'm not entirely convinced the distinction between "authorize" and "authenticate" is
enough, so the names might be confusing - I started with something like "UpgradeScopes" etc.
Regardless, better names welcome here.

I've tried to keep the names consistent, which made them verbose.
Better names welcome here too.
@mhammond mhammond force-pushed the push-mkxvwknxqksu branch from 735d3d7 to ad06176 Compare April 14, 2026 10:12
@mhammond
Copy link
Copy Markdown
Member Author

This looks pretty much correct to me, except I think there's one more step to do.

I agree, but not sure it should happen here? wdyt? Otherwise I think this seems ready to roll!

@mhammond
Copy link
Copy Markdown
Member Author

/taskcluster ci full

@mhammond mhammond changed the title Add new "Authorization" states and functions to authorize additional scopes. Add new "Authorization" states and functions to authorize additional scopes. [ci full] Apr 14, 2026
@mhammond mhammond requested review from jonalmeida April 14, 2026 10:27
@mhammond mhammond marked this pull request as ready for review April 14, 2026 10:28
Copy link
Copy Markdown
Contributor

@bendk bendk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this looks ready to roll to me. I had a couple questions/suggestions but I'm happy to merge as-is.

this.inner.completeOauthScopeAuthorizationFlow(code, state)
this.tryPersistState()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add these or is it better to force Android to use the state machine? I don't have strong feelings either way, just wanted to ask the question.

// On success, go directly to Connected — no InitializeDevice step needed since
// the device is already initialized.
(CompleteOAuthScopeAuthorizationFlow { .. }, CompleteOAuthFlowSuccess) => {
Complete(FxaState::Connected)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for another PR, but I think we should include the list of scopes as associated data for the Connect state. It's kind of weird that you went through a "state change" and ended up in the exact same state as before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants