Linkedin login is not working in Xamarin.Auth

Moon 1 Reputation point
2022-11-25T07:16:20.837+00:00

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....

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,325 questions
C#
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.
10,642 questions
{count} votes