Quantcast
Channel: Azure Active Directory forum
Viewing all articles
Browse latest Browse all 16000

Token getting expired during pulling users from Azure Active Group , how to create a valid token or extent the token validity.

$
0
0

Hi All,

I have a web application were i need to pull all the users from a given group present in Azure active directory.

When i login to the web site , able to pull the users present in the group, but after certain period ( say like 3 to 4 hrs ) encountering an error as below

{"odata.

error":{"code":"Authentication_ExpiredToken","message":{"lang":"en","value":"Your access token has expired. Please renew it before submitting the request."},"values":null}}

How to renew the token or else how to create a valid token

as of now using the below code

// Get a token for calling the Windows Azure Active Directory Graph
AuthenticationContext authContext = new AuthenticationContext(String.Format(CultureInfo.InvariantCulture,LoginURL, tenantId));
ClientCredential credential = new ClientCredential(Clientid,clientkey);
AuthenticationResult assertionCredential = authContext.AcquireToken(GraphURL, credential);
string authHeader = assertionCredential.CreateAuthorizationHeader();

string requestUrl = String.Format(
   CultureInfo.InvariantCulture,
   ConfigHelper.AdminGraphUserUrl,
   HttpUtility.UrlEncode(tenantId));

HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
request.Headers.TryAddWithoutValidation("Authorization", authHeader);
HttpResponseMessage response = await client.SendAsync(request);
string responseString = await response.Content.ReadAsStringAsync();


dynamic dynJson = JsonConvert.DeserializeObject(responseString);

Thanks,

Sai.


Viewing all articles
Browse latest Browse all 16000

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>