1

我想使用 keycloak 来角色基础访问控制。到目前为止,我不太了解关键斗篷是如何工作的。

我可以通过以下命令获取 access_token。

curl \
-d "username=admin" \
-d "password=MY_PASSWORD" \
-d "client_id=MY_CLIENT" \
-d "grant_type=password" \
"https://MY_DOMAIN/auth/realms/MY_REALM/protocol/openid-connect/token"

我的 WebAPI 是由 Rocket (rust) 制作的。所以没有准备好的keycloak适配器。

我想我需要在每次访问我的 WebAPI 时检查客户端给定的令牌。

这是我的处理程序。

///handler
#[get("/")]                                                                                
pub fn myhandler(_key:ApiKey,conn: DbConn) -> Option<JsonValue> 

pub struct ApiKey(String); 
impl<'a, 'r> FromRequest<'a, 'r> for ApiKey {                                                                                                                                                               
    type Error = ApiKeyError;                                                                                                                                                                               

    fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {                                                                                                                      
        let keys: Vec<_> = request.headers().get("x-api-key").collect();                                                                                                                                    
        //ask keycloak server that keys[0] is valid access_token??                                                                                                                                                                                              
    }                                                                                                                                                                                                       
}   

我发现keycloak上有一些端点。我应该使用哪个?

{

    // some claims are expected here

    // these are the main claims in the discovery document about Authorization Services endpoints location
    "token_endpoint": "http://${host}:${port}/auth/realms/${realm}/protocol/openid-connect/token",
    "token_introspection_endpoint": "http://${host}:${port}/auth/realms/${realm}/protocol/openid-connect/token/introspect",
    "resource_registration_endpoint": "http://${host}:${port}/auth/realms/${realm}/authz/protection/resource_set",
    "permission_endpoint": "http://${host}:${port}/auth/realms/${realm}/authz/protection/permission",
    "policy_endpoint": "http://${host}:${port}/auth/realms/${realm}/authz/protection/uma-policy"
}
4

0 回答 0