HarleyAuthXamarin/HarleyAuthXamarin/HarleyAuthXamarin/MainPage.xaml.cs
/// <summary>
/// GET request to an authorized endpoint using the GlobalSettings.AuthToken as the bearer token.
/// Popup the response.
/// </summary>
GET request to an authorized endpoint using the GlobalSettings.AuthToken as the bearer token.
Popup the response.
GET request to an authorized endpoint using the GlobalSettings . AuthToken as the bearer token . Popup the response .
public async void OnGetProtectedResourceButtonClicked(object sender, EventArgs args)
		{
			var authToken = GlobalSettings.AuthToken;
			if (authToken == null)
			{
				return;
			}
			var client = new HttpClient();
			client.BaseAddress = new Uri($"{GlobalSettings.BackendUrl}/");
			client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
			var responseMessage = await client.GetAsync($"api/values/auth");
			var responseJson = await responseMessage.Content.ReadAsStringAsync();
			await (Application.Current as App).MainPage.DisplayAlert("Protected Resource response", responseJson, "Ok");
		}
public async void OnGetProtectedResourceButtonClicked ( object sender , EventArgs args ) { var authToken = GlobalSettings . AuthToken ; if ( authToken == null ) { return ; } var client = new HttpClient ( ) ; client . BaseAddress = new Uri ( $" { GlobalSettings . BackendUrl } / " ) ; client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( " " , authToken ) ; var responseMessage = await client . GetAsync ( $" api/values/auth " ) ; var responseJson = await responseMessage . Content . ReadAsStringAsync ( ) ; await ( Application . Current as App ) . MainPage . DisplayAlert ( " " , responseJson , " " ) ; }
GET request to an authorized endpoint using the GlobalSettings.AuthToken as the bearer token.
GET request to an authorized endpoint using the GlobalSettings . AuthToken as the bearer token .
sender
object
args
EventArgs