Reputation: 11
I have create a WFC application to push the Data into Dynamics CRM. For Authentication with Dynamics CRM i am using Application User (S2S authentication)and In WFC i am getting access token using below code:
string ClientId = "********-542e-440b-b718-69f7826ae60a"; // App Id
string ClientSecret = "*******Ovm4/00jU?tYT.tw5t6a5@@8n";
string resource = "https://*****.crm8.dynamics.com";
ClientCredential clientcred = new ClientCredential(ClientId, ClientSecret);
var result = authenticationContext.AcquireToken(resource, clientcred);
Every thing is working fine till 1 hour after that i am getting 401(Unauthorized) error because access token getting expired after 1 hour.
Now My question is :-
Can i increase the access token life more than 1 hour, which is coming as 1 hour by default is 1 hour?
Using above mentioned code why i am only getting access token but not getting refresh token? (which we can use to refresh my access token). Please help me on this.
Upvotes: 1
Views: 763
Reputation: 58875
You don't get a refresh token because ADAL handles them internally. And you don't need one anyway in this case.
You can get a new token by calling AcquireToken
again:
var result = authenticationContext.AcquireToken(resource, clientcred);
Actually, you can call AcquireToken before every HTTP call. ADAL will give you a token from its memory cache if it is still valid, and get a new one if it does not have one.
Though since you are using client credentials flow, there is actually no refresh token returned ever. Because a client app like this does not need it. You have all the credentials to get new tokens with them anyway, a refresh token would only needlessly complicate the flow here.
Upvotes: 1