首页 > 解决方案 > 如何重用获取方法的访问令牌?我想调用扩展 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 "";

}

标签: c#asp.net-web-apihttpclientaccess-tokenrefresh-token

解决方案


API ( https://api.elliemae.com/oauth2/v1/token )中未实现刷新令牌功能。

如果支持,您将通过 access_token 获得 refresh_token,通过使用 refresh_token,您可以在 access_token 到期后更新您的 access_token。这就是 OAuth 2.0 所说的。


推荐阅读