postman - Postman Restsharp 的 Windows 身份验证
问题描述
目前,
我使用 Postman Restsharp 在iphone Safari mobile 中检索 JWT 令牌。
请问如何添加Windows认证?
我尝试了以下方法,但无法检索响应数据。
但它在公司笔记本电脑上工作。
var client = new RestClient("https://mvponduty.com/XChange_App_Api/api/auth/authenticate");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.UseDefaultCredentials = true;
request.AddHeader("Content-Type", " application/json; charset=utf-8");
request.AddHeader("Access-Control-Allow-Origin", " *");
request.AddHeader("Cache-Control", " no-cache");
request.AddHeader("Pragma", " no-cache");
request.AddHeader("Cookie", ".AspNetCore.Session=CfDJ8AoxL%2BrAgZtDtnzh7ZplJfx4moiRGYT4rFtA6zp%2B1d8CAQ4D%2FZary6IvN%2Ftjm7wl2Ke992wbhnP7cmv3q7ba0%2BQoZKHuT%2B2FyJzIAjaJFH2GX0ZFiz1nHdSLyGhPMrG4KCNXZ94u79I7DHKjVAxcREfISUxxrFnxib0Aw1Q4yNQw");
request.AddParameter(" application/json; charset=utf-8", "", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
解决方案
我使用另一种方法来生成 JWT Token。
string key = "iNivDmHLpUA223sqsfhqGbMRdRj1PVkH";
// Create Security key using private key above:
// not that latest version of JWT using Microsoft namespace instead of System
var securityKey = new Microsoft
.IdentityModel.Tokens.SymmetricSecurityKey(Encoding.UTF8.GetBytes(key));
// Also note that securityKey length should be >256b
// so you have to make sure that your private key has a proper length
//
var credentials = new Microsoft.IdentityModel.Tokens.SigningCredentials
(securityKey, SecurityAlgorithms.HmacSha256Signature);
// Finally create a Token
var header = new JwtHeader(credentials);
//Some PayLoad that contain information about the customer
var payload = new JwtPayload
{
{ "sub", "hello "},
{ "scope", "http://dummy.com/"},
};
var secToken = new JwtSecurityToken(header, payload);
var handler = new JwtSecurityTokenHandler();
// Token to String so you can use it in your client
var tokenString = handler.WriteToken(secToken);
Console.WriteLine(tokenString);
推荐阅读
- python-3.x - 使用 Tensorflow Probability 的 RandomWalkMetropolis 函数执行 RandomWalk 步骤
- batch-file - 使用 Windows 批处理脚本在文件创建日期中获取月份和年份
- javascript - 从切换列表中获取值
- java - 如何使用整理器按属性排序?(爪哇)
- jenkins - 无法使用 Jenkins 配置 Gitlab 实验室
- swift - 使用 Swift Combine 创建一个 Timer Publisher
- java - 我们应该如何验证正则表达式语法
- python - 需要从表中删除 2 列
- c++ - 链接 C++ 项目后 CodeBlocks 无法找到 C 库(Windows、GNU GCC 编译器)
- css - 测试 VueJS 应用程序可视化端