【问题标题】:Getting 404 not found error while accessing keycloak API method访问 keycloak API 方法时出现 404 not found 错误
【发布时间】:2019-01-28 06:05:32
【问题描述】:

我正在使用邮递员访问 keycloak api 方法以进行推理,以避免在我的 Angular 应用程序中将密钥斗篷页面作为登录页面。我正在从属于主领域获取 access_token,但是在使用令牌作为我的请求的授权承载令牌访问另一个领域(为特定于 Angular 应用程序而创建)时,得到 404 not found 错误。

注意:如果我在令牌中添加任何垃圾值附加它表示 401 未授权

邮递员截图

got access_token from master realm

accessing other realm with bearer token

【问题讨论】:

    标签: api keycloak keycloak-services


    【解决方案1】:

    在使用他们的 RESTful API 时应该有一个基本路径 /auth/admin/realms//admin/realms 部分在their documents 中所述的基本路径中丢失。

    1. 使用此端点获取访问令牌:/auth/realms/master/protocol/openid-connect/token
    2. 使用令牌调用 RESTful 管理 API。
    KEYCLOAK_TOKEN=$(curl -X POST "${KEYCLOAK_URL}/auth/realms/master/protocol/openid-connect/token" \
     -H "Content-Type: application/x-www-form-urlencoded" \
     -d "username=admin" \
     -d "password=admin-password" \
     -d 'grant_type=password' \
     -d 'client_id=admin-cli' | jq -r '.access_token')
    
    curl "${KEYCLOAK_URL}/auth/admin/realms/${KEYCLOAK_REALM}/users" -H "Authorization: Bearer ${KEYCLOAK_TOKEN}" 
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-12
    • 2017-09-03
    • 1970-01-01
    • 2017-11-25
    • 2016-10-05
    • 2017-10-19
    • 2018-07-19
    • 1970-01-01
    相关资源
    最近更新 更多