我应该使用哪些密钥隐藏端点?

时间:2020-05-24 01:58:39

标签: keycloak-rest-api

我想使用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是由火箭(生锈)制成的。因此,没有准备好的密钥转换适配器。

我认为我需要在每次访问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??                                                                                                                                                                                              
    }                                                                                                                                                                                                       
}   

我发现密钥斗篷上有一些终结点。我应该使用哪个?

{

    // 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"
}

0 个答案:

没有答案