-1

I have the following code which gives me a Access token, now that I have finally been able to access a token I realized this token will expire, so what can I do to keep refreshing the token, and use it to grab vaules in my get method

Postman Image (the data I want) : Image here

ValuesController.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 "";

}
fay
  • 13
  • 9
  • accesstoken is already in place that's giving people the visual to let them know where I am currently – fay Jun 11 '19 at 15:18
  • if your token expired...... just get a new one (like you just got the first one), you can increase the expiration time if that helps – MorenajeRD Jun 11 '19 at 15:22
  • Well how do I use this access token on a GET method, I want to extend a retrieve data through my access token – fay Jun 11 '19 at 15:23
  • Your question doesn't fit will with the code you've shown so it's hard to answer. Maybe this info would help you make your question more clear. https://learn.microsoft.com/en-us/aspnet/web-api/overview/security/external-authentication-services – MikeJ Jun 11 '19 at 16:18

1 Answers1

0

Refresh token functionality is not implemented in the API (https://api.elliemae.com/oauth2/v1/token).

if had supported, you would get the refresh_token along access_token, by using refresh_token you could update your access_token after its expiry. This is what OAuth 2.0 says.

saqib abbas
  • 71
  • 1
  • 3