会话的 Azure App Services Exchange AuthenticationToken

Azure App Services Exchange AuthenticationToken for Session

根据文档 (https://azure.microsoft.com/en-us/blog/announcing-app-service-authentication-authorization/) 客户端可以使用 HTTP POST 将访问令牌更新到 /.auth/login/[提供商名称]

"Alternatively, a client can obtain a token using a provider SDK and exchange it for a session token. Simply submit an HTTP POST to the same endpoint with the provider token in a JSON body under the key “access_token” (or “authenticationToken” for Microsoft Account)."

或者,客户端可以使用提供商 SDK 获取令牌并将其交换为会话令牌。只需将 HTTP POST 提交到同一端点,并在密钥“access_token”(或 Microsoft 帐户的“authenticationToken”)下的 JSON 正文中提供提供商令牌。 “

我正在使用 facebook 并且能够 POST 我直接从 facebook 收到的 access_key 到 /.auth/login/facebook 端点。但是,响应在以下架构中:

{
    "authenticationToken":[string value],
    "user": {
       "userId": "sid:[hex value]"
     }
}

似乎没有关于如何将其交换为会话令牌的任何文档and/or Web 版本似乎可以使用的 AppServiceAuthSession cookie。

仅供参考 - 我现在只想使用直接的 HTTP / REST 实现而不是任何 SDK。

看来您的方向是正确的。在您返回的 JSON 有效负载中,authenticationToken 是文档引用的 session 令牌:

{
    "authenticationToken":[this is your session token],
    "user": {
       "userId": "..."
     }
}

使用 SDK 时,此值会自动解析并用于所有后续 API 对后端服务的调用。如果您直接使用 REST,则可以使用您希望的任何 JSON 库解析此令牌,然后使用 x-zumo-auth HTTP 将其附加到您对服务 API 进行的任何 HTTP 调用请求 header.

例如:

GET /api/values
x-zumo-auth: [session token from the previous step]

希望对您有所帮助。