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

[PLATFORM-1195]: rfc8414 compliance #44

Merged
merged 8 commits into from
Aug 22, 2023
Merged

[PLATFORM-1195]: rfc8414 compliance #44

merged 8 commits into from
Aug 22, 2023

Conversation

MaeIsBad
Copy link
Member

match token_request {
TokenRequest::ClientCredentials(request) => jwt_for_client_credentials(app_data, request).await,
TokenRequest::AuthorizationCode(request) => jwt_for_authorization_code(app_data, request).await,
}
}

impl token {
pub const ENDPOINT: &str = "/oauth/token";
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't like so much to have a string replicated. Can we change how routings are made and instead of using service and #[post macro use this kind of build pattern?

web::resource(controller::token::ENDPOINT)
        .route(web::post().to(controller::token)))

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't really like that, it's quite ugly. I don't like repeating the string either, but I prefer doing it this way

for reference, here is a cleaned up version of the #[post] macro

struct token;
impl HttpServiceFactory for token {
    fn register(self, cfg: &mut actix_web::dev::AppService) {
        /// Generate a new jwt token for a given audience. For `client_credentials` the audience is found in the post body
        /// and for `authorization_code` the audience is found in the authorizations cache.
        /// All the permissions found in the local store will be included in the generated token.
        async fn token(
            app_data: Data<AppData>,
            token_request: Either<Json<TokenRequest>, Form<TokenRequest>>,
        ) -> HttpResponse {
            let (
                Either::Left(Json(token_request))
                | Either::Right(Form(token_request))
            ) = token_request;
            match token_request {
                TokenRequest::ClientCredentials(request) => {
                    jwt_for_client_credentials(app_data, request).await
                }
                TokenRequest::AuthorizationCode(request) => {
                    jwt_for_authorization_code(app_data, request).await
                }
            }
        }
        let res = Resource::new("/oauth/token")
            .name("token")
            .guard(::actix_web::guard::Post())
            .to(token);
        HttpServiceFactory::register(res, cfg)
    }
}

src/model/openid_metadata.rs Show resolved Hide resolved
@MaeIsBad MaeIsBad requested a review from cottinisimone August 1, 2023 12:03
@MaeIsBad MaeIsBad requested a review from a team as a code owner August 22, 2023 09:13
cottinisimone
cottinisimone previously approved these changes Aug 22, 2023
@MaeIsBad MaeIsBad merged commit f77238b into master Aug 22, 2023
@MaeIsBad MaeIsBad deleted the oidc-metadata branch August 22, 2023 09:32
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