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

Implement an async version of client credentials flow #159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mtelahun
Copy link

This is an attempt to port client credentials flow to the async version. I noticed that it seemed to be the only implemented flow that was missing an async version. I didn't know if this was a deliberate omission or not, but after some investigation I realized that the async work was done much earlier. So, I decided to try my hand at porting it over. The work itself doesn't contain anything new. It's a straight up port of the non-synchronous code to an async version. Please let me know if I missed anything. Also, I would appreciate any comments on the minor changes in oxide-auth that are needed to get the async version to compile (like changing the visibility of a couple of functions and ::new() constructor in a couple of places).

  • [*] I have read the [contribution guidelines][Contributing]
  • [*] This change has tests (remove for doc only)
  • [*] This change has documentation

I license past and future contributions under the dual MIT/Apache-2.0 license, allowing licensees to chose either at their option.

Copy link
Owner

@HeroicKatora HeroicKatora left a comment

Choose a reason for hiding this comment

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

Reviewing the logic of the async state machine will take a short time and a breather, it being security critical. I like the suggestion and generic implementation though, just review the amount of items made public. Good encapsulation should not be lost.

@@ -121,7 +121,7 @@ pub enum ResponseStatus {
/// not derive this until this has shown unlikely but strongly requested. Please open an issue if you
/// think the pros or cons should be evaluated differently.
#[derive(Debug)]
enum InnerTemplate<'a> {
pub enum InnerTemplate<'a> {
Copy link
Owner

Choose a reason for hiding this comment

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

Can you add and use constructors to Template instead.

Comment on lines +536 to +538
pub fn new(error: AccessTokenError) -> Self {
Self { error }
}
Copy link
Owner

Choose a reason for hiding this comment

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

Being critical towards making too many internals public applies here, too, the constructor should only be needed by the response template internally. There's already constructors applicable to new_ok and new_unauthorized for instance.

Comment on lines +649 to +651
pub fn new(token: IssuedToken, scope: String) -> BearerToken {
Self(token, scope)
}
Copy link
Owner

Choose a reason for hiding this comment

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

That should definitely not be the public signature, consider making the second parameter &Scope. But it's slightly controversial either way. This type consciously does not have a public constructor to nudge you towards properly using the flow and not issuing a badly protected token (e.g. to unauthenticated parties). I'll need to consider this, maybe you have arguments pro/con?

How complicated is it to duplicate? Seriously consider this alternative as well.

@mtelahun
Copy link
Author

@HeroicKatora Thanks for the feedback. I will update the PR as requested.

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