HarleyAuthXamarin/HarleyAuthXamarin/HarleyAuthXamarin/MainPage.xaml.cs
/// <summary>
/// POST the GlobalSettings.FacebookToken to our facebook login endpoint on the api service.
/// Save the JWT token we get back and popup the result.
/// </summary>
POST the GlobalSettings.FacebookToken to our facebook login endpoint on the api service.
Save the JWT token we get back and popup the result.
POST the GlobalSettings . FacebookToken to our facebook login endpoint on the api service . Save the JWT token we get back and popup the result .
public async void OnServiceAuthenticateButtonClicked(object sender, EventArgs args)
		{
			var facebookToken = GlobalSettings.FacebookToken;
			if (facebookToken == null)
			{
				return;
			}
			var client = new HttpClient();
			client.BaseAddress = new Uri($"{GlobalSettings.BackendUrl}/");
			var content = new StringContent("{\"AccessToken\":\"" + facebookToken + "\"}", Encoding.UTF8, "application/json");
			var responseMessage = await client.PostAsync($"/api/ExternalAuth/facebook", content);
			var responseJson = await responseMessage.Content.ReadAsStringAsync();
			if (responseMessage.IsSuccessStatusCode)
			{
				var responseObject = JsonConvert.DeserializeObject<AuthResponse>(responseJson);
				GlobalSettings.AuthToken = responseObject.auth_token;
				await (Application.Current as App).MainPage.DisplayAlert("AuthResponse to service", responseObject.auth_token, "Ok");
			}
			else
			{
				await (Application.Current as App).MainPage.DisplayAlert("AuthResponse to service", responseMessage.StatusCode.ToString(), "Ok");
			}
		}
public async void OnServiceAuthenticateButtonClicked ( object sender , EventArgs args ) { var facebookToken = GlobalSettings . FacebookToken ; if ( facebookToken == null ) { return ; } var client = new HttpClient ( ) ; client . BaseAddress = new Uri ( $" { GlobalSettings . BackendUrl } / " ) ; var content = new StringContent ( " \" \" \" " + facebookToken + " \" " , Encoding . UTF8 , " " ) ; var responseMessage = await client . PostAsync ( $" /api/ExternalAuth/facebook " , content ) ; var responseJson = await responseMessage . Content . ReadAsStringAsync ( ) ; if ( responseMessage . IsSuccessStatusCode ) { var responseObject = JsonConvert . DeserializeObject < AuthResponse > ( responseJson ) ; GlobalSettings . AuthToken = responseObject . auth_token ; await ( Application . Current as App ) . MainPage . DisplayAlert ( " " , responseObject . auth_token , " " ) ; } else { await ( Application . Current as App ) . MainPage . DisplayAlert ( " " , responseMessage . StatusCode . ToString ( ) , " " ) ; } }
POST the GlobalSettings.FacebookToken to our facebook login endpoint on the api service.
POST the GlobalSettings . FacebookToken to our facebook login endpoint on the api service .
sender
object
args
EventArgs