public static async void BeginAuthentication() { // First, look for the authority used during the last authentication. // If that value is not populated, use CommonAuthority. string authority = null; if (String.IsNullOrEmpty(App._settings.LastAuthority)) { authority = CommonAuthority; } else { authority = App._settings.LastAuthority; } AuthenticationContext = await AuthenticationContext.CreateAsync(authority); AuthenticationContext.AcquireTokenAndContinue(DiscoveryResourceId, ClientID, _returnUri, null); }
public static async void BeginAuthentication(Action<UserLoginResponse> responseConsumer) { //First, look for the authority used during the last authentication. //If that value is not populated, use CommonAuthority. string authority = null; if (String.IsNullOrEmpty(LastAuthority)) { authority = CommonAuthority; } else { authority = LastAuthority; } _authenticationContext = await AuthenticationContext.CreateAsync(authority); _authenticationContext.AcquireTokenAndContinue(ResourceID, ClientID, _returnUri, async result => { HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken); var response = await httpClient.GetAsync(ApiUserDetails); if (response.IsSuccessStatusCode) { string jsonResult = await response.Content.ReadAsStringAsync(); UserLoginResponse loginResponse = JsonConvert.DeserializeObject<UserLoginResponse>(jsonResult); loginResponse.AccessToken = result.AccessToken; loginResponse.RefreshToken = result.RefreshToken; responseConsumer(loginResponse); } }); }