最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Verify Keycloak Token from React Frontend in my Flask Python Server using a JWTBearerTokenValidator - Stack Overflow

programmeradmin8浏览0评论

I want to verify a Token that is sent to my server using authlib and Keycloak. This is my current setup, although it is not working. Somehow the token in the validate_token() method is always None.

class ClientCredsTokenValidator(JWTBearerTokenValidator):
def __init__(self, issuer):
    certs = keycloak_openid.certs()
    public_key = JsonWebKey.import_key_set(certs)
    super(ClientCredsTokenValidator, self).__init__(public_key)
    self.claims_options = {
        "exp": {"essential": True},
        "iss": {"essential": True, "value": issuer},
    }

def validate_token(self, token, scopes, request):
    super(ClientCredsTokenValidator, self).validate_token(token, scopes, request)


require_auth = ResourceProtector()
validator = ClientCredsTokenValidator(KEYCLOAK_ISSUER)
require_auth.register_token_validator(validator)

My app route I try to fetch looks like this:

@app.route('/loans/all', methods=['GET'])
@require_auth(None)
def get_all_loans():
    ...

The keycloak_openid.certs() is a package fetch the certificates from my keycloak instance, which is hosted in a docker container on my local machine.

What am I missing?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论