Xamarin Auth google login not redirect to app in ios

Natarajan Tulasi 21 Reputation points
2021-08-12T09:54:42.933+00:00

I am Integrating google drive in Xamarin app. The google login presenter is opening and I select my account and give access to the app. but it does not redirect to my app and it shows error "File /outh2redirect does not exist".

My config for redirect url is I tried both client ID and url schema like this

public static readonly string RedirectUrl = "com.googleusercontent.apps.xxxxxxxxxxxxxxxxxxxxxx:/oauth2redirect";

and

public static readonly string RedirectUrl = "net.zavy.xamforms/oauth2redirect";

and my info plist file after added URL Types is

122683-screenshot-2021-08-12-at-24535-pm.png

If anyone fixed this kind of issue please tell me

Thanks

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,362 questions
{count} votes

Accepted answer
  1. Kyle Wang 5,531 Reputation points Microsoft Vendor
    2021-08-18T07:56:00.003+00:00

    Hi NatarajanTulasi-6244,

    Welcome to our Microsoft Q&A platform!

    I tested the demo you provided, but did not get the error "File /outh2redirect does not exist". Besides, to redirect the url to the app, try to override OpenUrl in AppDelegate.cs.

    public override bool OpenUrl(UIApplication application, NSUrl url, NSDictionary options)  
    {  
        var uri = new Uri(url.AbsoluteString);  
        var googleDriveInstance = GoogleDriveSingelton.GetInstance;  
        googleDriveInstance.auth?.OnPageLoading(uri);  
      
        return true;  
    }  
    

    Then you modify the scope in GoogleConfig as follows:

    public static string scope = "https://www.googleapis.com/auth/userinfo.email";  
    

    Now you can get the account logged in.

    private async void Auth_Completed(object sender, AuthenticatorCompletedEventArgs e)  
    {  
        if (e.IsAuthenticated)  
        {  
            var request = new OAuth2Request("GET", new Uri("https://www.googleapis.com/oauth2/v2/userinfo"), null, e.Account);  
            var response = await request.GetResponseAsync();  
            string account_info = await response.GetResponseTextAsync();  
        }  
    }  
    

    Regards,
    Kyle


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Afzal Saeed 1 Reputation point
    2021-08-30T20:27:17.52+00:00

    @Natarajan Tulasi I am stuck in same problem in android , can you please help me with sample ??


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.