Passing and verifying the OWIN Bearer token in Query String in WebAPI

前端 未结 3 2058
悲&欢浪女
悲&欢浪女 2020-12-31 03:22

Short Version: I need to pass and verify the OWIN bearing token as a query parameter rather than in the request header.

How do I then get the method to authorized ba

3条回答
  •  鱼传尺愫
    2020-12-31 03:39

    or do it like this

        app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
        {
            Authority = IdentityConfig.Authority,
            RequiredScopes = new[] { "api" },
            TokenProvider = new OAuthBearerAuthenticationProvider
            {
                OnRequestToken = ctx =>
                {
                    if (String.IsNullOrWhiteSpace(ctx.Token) && ctx.Request.QueryString.HasValue)
                    {
                        NameValueCollection parsedQuery = HttpUtility.ParseQueryString(ctx.Request.QueryString.Value);
                        ctx.Token = parsedQuery["access_token"];
                    }
    
                    return Task.FromResult(0);
                }
            }
        });
    

提交回复
热议问题