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

Please add a common trait for token requests #142

Open
Natureshadow opened this issue May 14, 2021 · 0 comments
Open

Please add a common trait for token requests #142

Natureshadow opened this issue May 14, 2021 · 0 comments

Comments

@Natureshadow
Copy link

Natureshadow commented May 14, 2021

I am writing a wrapper function that takes some configuration, then builds a request object with exchanged credentials (by calling the respective exchange_* methods on BasicClient).

The returned object is of one of the types in https://docs.rs/oauth2/4.0.0/oauth2/struct.ClientCredentialsTokenRequest.html?search=tokenrequest – however, these objects do not share a common trait, so cannot be returned by the same function and used the same way by the caller.

Ass all the *TokenRequest objects have the same API, it would be helpful to have a common trait that can be used as a type.

Along these lines, something like this:

pub enum Credentials {
    ClientCredentials,
    PasswordCredentials(String, String),
    // ...
}

pub fn exchange_credentials(&self, c: Credentials) -> TokenRequestTrait {
    match c {
        Credentials::ClientCredentials -> self.exchange_client_credentials(),
        Credentials::PasswordCredentials(u, p) -> self.exchange_password_credentials(...),
        //...
    }
}

would probably be a good idea as well.

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

No branches or pull requests

1 participant