/// <summary> /// Retrieves access token from LWA /// </summary> /// <param name="lwaAccessTokenRequestMeta">LWA AccessTokenRequest metadata</param> /// <returns>LWA Access Token</returns> public virtual string GetAccessToken() { LWAAccessTokenRequestMeta lwaAccessTokenRequestMeta = LWAAccessTokenRequestMetaBuilder.Build(LWAAuthorizationCredentials); var accessTokenRequest = new RestRequest(LWAAuthorizationCredentials.Endpoint.AbsolutePath, Method.POST); string jsonRequestBody = JsonConvert.SerializeObject(lwaAccessTokenRequestMeta); accessTokenRequest.AddParameter(JsonMediaType, jsonRequestBody, ParameterType.RequestBody); string accessToken; try { var response = RestClient.Execute(accessTokenRequest); if (!IsSuccessful(response)) { throw new IOException("Unsuccessful LWA token exchange", response.ErrorException); } JObject responseJson = JObject.Parse(response.Content); accessToken = responseJson.GetValue(AccessTokenKey).ToString(); } catch (Exception e) { throw new SystemException("Error getting LWA Access Token", e); } return(accessToken); }
public LWAClient(LWAAuthorizationCredentials lwaAuthorizationCredentials) { LWAAuthorizationCredentials = lwaAuthorizationCredentials; LWAAccessTokenRequestMetaBuilder = new LWAAccessTokenRequestMetaBuilder(); RestClient = new RestClient(LWAAuthorizationCredentials.Endpoint.GetLeftPart(System.UriPartial.Authority)); }