c# - 如何重用获取方法的访问令牌?我想调用扩展 URL 来接收数据
问题描述
我有以下代码,它给了我一个访问令牌,现在我终于能够访问一个令牌,我意识到这个令牌将过期,所以我能做些什么来不断刷新令牌,并用它来获取我的 get方法
值控制器.Cs
namespace APICredential.Controllers
{
[RoutePrefix("api")]
public class ValuesController : ApiController
{
[HttpGet, Route("values")]
public async Task<string> Post()
{
using (HttpClient client = new HttpClient())
{
client.BaseAddress = new Uri("https://api.elliemae.com/oauth2/");
var parameters = new Dictionary<string, string>()
{
{"grant_type", "password"}, //Gran_type Identified here
{"username", "admin@encompass:BE11200822"},
{"password", "Shm******"},
{"client_id", "gpq4sdh"},
{"client_secret", "dcZ42Ps0lyU0XRgpDyg0yXxxXVm9@A5Z4ICK3NUN&DgzR7G2tCOW6VC#HVoZPBwU"},
{"scope", "lp"}
};
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "v1/token")
{
Content = new FormUrlEncodedContent(parameters)
};
HttpResponseMessage response = await client.SendAsync(request);
string result = await response.Content.ReadAsStringAsync();
return result;
}
}
[HttpGet, Route("values/{id}")]
public string Get(int id)
{
return "";
}
解决方案
API ( https://api.elliemae.com/oauth2/v1/token )中未实现刷新令牌功能。
如果支持,您将通过 access_token 获得 refresh_token,通过使用 refresh_token,您可以在 access_token 到期后更新您的 access_token。这就是 OAuth 2.0 所说的。
推荐阅读
- javascript - 数组未在 Node.js 中重置
- javascript - 如何自动显示幻灯片的第一张图片
- batch-file - 如何在 CMD 中检测成功或不成功的 telnet 连接?
- vb.net - VB.Net - 如何最好地将大量数据写入 csv
- hl7-fhir - FHIR-Server-for-Azure 部署和调试
- javascript - JSDOM.serialize() 剥离结束链接标签
- sql - 如何在sql中获取从当天开始仅两小时分秒的数据
- javascript - 我的自动更正表格的值显示为零
- mysql - 想要 GROUP BY 包含在两个相似列中的所有值的组合集(而不是两个单独的列)
- python - 如何使用 Splinter 单击 html 占位符链接?- 说不可交互