2
I’m building an app (with Xamarin.Forms Pcl), where I have a login with facebook, using the Azure Mobile Client SDK. It is possible to perform the authentication, however, right after the authentication, I try to make a listing in the api url: https://adoteumamigo.azurewebsites.net/api/Tipo and have Unauthorized 401 Return.
Being that the login with the social network was carried out successfully. Follows the evidence:
Code where I have the problem:
public async Task<List<Tipo>> GetTipoAsync()
{
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = await httpClient.GetAsync($"{BaseUrl}Tipo").ConfigureAwait(false);
if (response.IsSuccessStatusCode)
{
using (var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
{
return JsonConvert.DeserializeObject<List<Tipo>>(
await new StreamReader(responseStream).ReadToEndAsync().ConfigureAwait(false));
}
}
return null;
}
Observing: Before placing authentication with facebook, accessing the api and getting the data for listing worked properly. The problem is because you are giving this access without authorization in the url, even after being logged in. Observation 2: You can test the api in the browser, with facebook authentication, and it works correctly.
Is using the class
MobileServiceClient
for authentication on Facebook?– rubStackOverflow
@rubStackOverflow I am. Authentication works, soon on facebook, Mobileservicecliente returns me sid and token. Now in the morning I searched, and I found something that may be the following: This token who is returning me is Azure, and I must get the token from facebook and at the time of listing the api, send the token from facebook... but I haven’t tested it yet. Makes sense?
– Erico Souza
Yeah, that’s right, that’s right.
– rubStackOverflow