使用仅Http-Only Cookie作为Jwt容器

时间:2017-02-28 16:10:23

标签: .net api authentication jwt cookie-httponly

我知道许多人可能不同意这种实现,但我希望将jwt存储在仅限http的容器中以防止javascript访问该令牌。一旦用户通过身份验证,.NET应用程序就会从Identity Server检索Jwt。然后我想创建一个仅限http的cookie并将jwt存储在其中,然后将其发送到api进行授权。

我想问一下如何将这个cookie发送到api,以及如何让api访问cookie中的jwt并使用Identity Server进行身份验证(我知道我可以使用Identity Server上的内省端点检查jwt是否有效。

我目前正在尝试使用RestSharp从应用程序发送请求:



Process.Start




这是我试图用来验证api上的jwt的代码:



Class ChocoClass
{
    [string] OutputToOverwrite()
    {
        return $this.FunctionToMock()
    }

    [string] FunctionToMock()
    {
        return "This text will be replaced"
    }
}


Describe "Testing mocking"{
    it "Mock test"{
        Mock FunctionToMock -MockWith {return "mystring"}
        $package = New-Object ChocoClass
        $expected = $package.OutputToOverwrite()
        $expected | should BeExactly "mystring"
    }
}




0 个答案:

没有答案