A Microsoft framework for building cross-platform mobile apps using .NET and C# with native performance and user interfaces.
Linkedin login is not working in Xamarin.Auth
Monalisha Swain
1
Reputation point
I am trying to authenticate and get user details from linkedin using xamarin forms. I am using Xamarin. Auth and Xamarin. Auth.XamarinForms.
private void OnLinkedInClicked()
{
try
{
var authenticator = new OAuth2Authenticator(
clientId: "***",
clientSecret: "****",
scope: "r_liteprofile",
authorizeUrl: new Uri("https://www.linkedin.com/uas/oauth2/authorization"),
redirectUrl: new Uri("***"),
accessTokenUrl: new Uri("https://www.linkedin.com/uas/oauth2/accessToken"),
null,
false);
var page = new AuthenticatorPage(authenticator);
authenticator.Completed += OnLinkedInAuthenticationComplete;
Application.Current.MainPage.Navigation.PushModalAsync(page);
}
catch (Exception ex)
{
}
}
private async void OnLinkedInAuthenticationComplete(object sender, AuthenticatorCompletedEventArgs e)
{
if (!e.IsAuthenticated)
{
//Show error message to the user
return;
}
try
{
// request user data from LinkedIn
var request = new OAuth2Request(
"GET",
new Uri("https://api.linkedin.com/v2/me?"
+ "format=json"
+ "&oauth2_access_token="
+ e.Account.Properties["access_token"]),
null,
e.Account);
request.AccessTokenParameterName = "oauth2_access_token";
var linkedInResponse = await request.GetResponseAsync();
var json = linkedInResponse.GetResponseText();
var user = GetUserFromLinkedInJson(json);
if (user == null) return;
ContinueToNextPage(user);
}
catch (Exception ex)
{
}
}
Though I am getting the access_ token But while requesting user data, linkedInResponse i.e request.GetResponseAsync();, is throwing this exception
{ "serviceErrorCode": 65601, "message": "The token used in the request has been revoked by the user", "status": 401 }
Any soultion plz....
Developer technologies | .NET | Xamarin
Developer technologies | .NET | Xamarin
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
Sign in to answer