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 OAuth 2.0 token introspection #55

Merged
merged 2 commits into from
Sep 5, 2024
Merged

Implement OAuth 2.0 token introspection #55

merged 2 commits into from
Sep 5, 2024

Conversation

centromere
Copy link
Contributor

This PR provides a bare-bones implementation of RFC 7662. Example usage:

#[derive(Debug, Deserialize, Serialize)]
struct Roles {
    roles: Vec<String>,
}

#[derive(Debug, Deserialize, Serialize)]
struct CustomKeycloakFields {
    realm_access: Roles,
    resource_access: HashMap<String, Roles>,
    name: String,
    email: String,
}

impl CompactJson for CustomKeycloakFields {}

async fn validator(req: ServiceRequest, credentials: BearerAuth) -> Result<ServiceRequest, (actix_web::Error, ServiceRequest)> {
    // ...
    let token = Token::from(openid::Bearer {
        access_token: String::from(credentials.token()),
        token_type: String::from("Bearer"),
        scope: None,
        state: None,
        refresh_token: None,
        expires_in: None,
        id_token: None,
        extra: None,
    });

    let introspection: TokenIntrospection<CustomKeycloakFields> = openid_client.request_token_introspection(&token).await.unwrap();
    if introspection.active {
        // ...
    } else {
        // ...
    }
}

@kilork
Copy link
Owner

kilork commented Sep 3, 2024

@centromere Hi, this looks really cool. What is the meaning of "Begin" here, do you mean there are more functions to cover from RFC? Could you add to README part about the RFC and support status (which features are implemented), if it is applicable?

@centromere centromere changed the title Begin implementation of token introspection Implement OAuth 2.0 token introspection Sep 3, 2024
@centromere
Copy link
Contributor Author

@kilork, Hi. The coverage seems complete to me. I wrote "Begin" because I anticipated needing to make changes to better conform to the project structure. I've added a note to the README and updated the commit.

@kilork
Copy link
Owner

kilork commented Sep 5, 2024

@centromere I did small corrections and going to merge it to master. The crate itself is a mix of two other crates, it is difficult to say, if project structure well defined or is it a result of evolution :)

@kilork kilork merged commit 094def9 into kilork:master Sep 5, 2024
1 check passed
@centromere centromere deleted the token-introspection branch September 6, 2024 14:34
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