Google 使用 App Engine Flexible 的 Cloud Endpoints 自定义身份验证 (Node.js)

Google Cloud Endpoints custom authentication with App Engine Flexible (Node.js)

Google Cloud Endpoints 文档为可扩展服务代理配置文件中的自定义安全定义提供了此规范:

securityDefinitions:
    your_custom_auth_id:
        authorizationUrl: ""
        flow: "implicit"
        type: "oauth2"
        # The value below should be unique
        x-google-issuer: "issuer of the token"
        x-google-jwks_uri: "url to the public key"
        # Optional. Replace YOUR-CLIENT-ID with your client ID
        x-google-audiences: "YOUR-CLIENT-ID"

对于 App Engine Flexible,关于如何实现它的文档非常少。有没有人有如何设置这个的例子,或者他们可以证明这是可能的?特别是 authorizationUrl 的接口是什么?我们能否放置授权服务的 URL(提供由可扩展服务代理验证的 JWT 令牌),以便在授权 URL 中令牌无效时端点将重定向到它?

你是对的。 'authorizationUrl' 是客户端用来检索实际 JWT(JSON Web 令牌)的 OpenAPI Swagger specific annotation which points to the URL endpoint of your log in form

一旦客户端在登录后从您的 App Engine 应用程序检索到 JWT,他们就可以使用它来授权他们对您的 Cloud Endpoint API 的请求。


您的 Node.js App Engine 应用程序将使用多种语言的任何 JWT signing library to generate the JWT (auth0 offers their own)。

要生成令牌,您将提供标准 'JWT' 和散列 headers,添加您的特定用户 object JSON 有效负载(因为此令牌应该是此特定用户独有),以及您的 secret/public 密钥。

JWT 库还应自动提供所需的 JWT claims while generating it, just ensure you supply the issuer used by the library and your secret/public key in your 'openapi.yaml' 作为 'x-google-issuer' 和 'x-google-jwks_uri'。


您可以按照JWT.io guide to learn more about how to generate and use a JWT. You can also follow the specific App Engine Flexible guide to code your application来处理JWT。