IdentityServer3访问令牌验证和预签名URL

时间:2016-02-29 17:58:21

标签: odata access-token identityserver3 bearer-token pre-signed-url

我有一个Web API 2 OData v3服务,该服务使用IdentityServer Bearer Token身份验证/访问令牌验证进行保护。客户端是SPA应用程序。我成功使用oidc-token-manager.js库进行身份验证,并使用XMLHttpRequest将Authorization http标头中的访问令牌传递给常规odata crud操作。

我的odata服务还支持上传和下载文件的流媒体。同样,对于上传文件,我可以使用XMLHttpRequest传入Authorization http头中的访问令牌。

但是,要下载文件,我想使用带有href的锚标签(odata文件下载网址通常为格式/ odata / myfiles(1)/ $ value)。当用户点击链接时,它应该下载文件(odata服务将内容处置附件标题添加到响应中)。

但是,无法在此GET请求的Authorization标头中添加访问令牌,因为它是由浏览器创建的。是否可以将访问令牌作为查询字符串添加到href中的url(所谓的预签名URL)?这甚至是一个好的(安全的)想法吗?在服务器上我在我的Startup.cs中使用了app.UseIdentityServerBearerTokenAuthentication,那么这是否能够在查询字符串和Authorization http头中查找访问令牌?

非常感谢

REMCO

1 个答案:

答案 0 :(得分:1)

您可以注册"提供商"控制令牌的位置逻辑。例如:

app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
{
    // locate the access token from somewhere else
    Provider = new OAuthBearerAuthenticationProvider
    {
        OnRequestToken = async ctx =>
        {
            ctx.Token = await YourCodeToFindTokenInQueryString(ctx.OwinContext.Environment);
        }
    },

   //
};