How to get error message returned by DotNetOpenAuth.OAuth2 on client side?

后端 未结 3 1505
Happy的楠姐
Happy的楠姐 2020-12-13 07:07

I\'m using ExchangeUserCredentialForToken function to get the token from the Authorization server. It\'s working fine when my user exists in my databas, but whe

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-13 07:31

    Jeff's solution does not work for me, but when I use OnSendingHeaders it works fine:

    public class InvalidAuthenticationMiddleware : OwinMiddleware
    {
        public InvalidAuthenticationMiddleware(OwinMiddleware next) : base(next) { }
    
        public override async Task Invoke(IOwinContext context)
        {
            context.Response.OnSendingHeaders(state =>
            {
                var response = (OwinResponse)state;
    
                if (!response.Headers.ContainsKey("AuthorizationResponse") && response.StatusCode != 400) return;
    
                response.Headers.Remove("AuthorizationResponse");
                response.StatusCode = 401;
    
            }, context.Response);
    
            await Next.Invoke(context);
        }
    }
    

提交回复
热议问题