Forum General


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Redirect URL for google oauth?

Billy12ShovelsBilly12Shovels USUniversity ✭✭✭


Does anyone know the default redirect url for google oauth? I have tried logic based on this github link(line 18):

and that does not work. Any ideas?



Best Answer


  • RobStellerRobSteller USMember ✭✭

    Were you able to figure this out?

  • Billy12ShovelsBilly12Shovels USUniversity ✭✭✭
    Accepted Answer

    I was using "xamarin-auth://localhost" as the redirecut url, but I ended up not implementing the functionality and instead used Auth0 for my login flow.

  • RobStellerRobSteller USMember ✭✭


  • moljacmoljac HRBeta ✭✭✭

    xamarin-auth://localhost is indeed custom url, but it can be used (with google) only with "Other" app/client type.

    You must read google docs during setup of the OAuth provider - for Android it has 2 options (based on package id from AndroidManifest.xml and google product id - the second one works the best). IOS has different setup (Info.plist and any kind of scheme). If you add UWP to that you will have new issues, but solvable. The same is valid for Xamarin.Forms.

    Basically it is not trivial and needs some planing.

  • I am trying to use "com.googleusercontent.apps.5**************"; as a redirect url but it can not be converted to an uri and use it in the OAuth2Authenticator.

  • KlinguKlingu USMember ✭✭

    @BrunoPasquini.7813 said:
    I am trying to use "com.googleusercontent.apps.5**************"; as a redirect url but it can not be converted to an uri and use it in the OAuth2Authenticator.

    You should add ":/oauth2redirect" at the end of your redirectUrl. Like below ;-)


    Allmost there ;-)

  • AlexOwensAlexOwens USMember

    I am attempting to use the OAuth2Authenticator as well, I've added the :/oauth2redirect to my reverse client Id; however, when I login using this method, I see a google search page. Any ideas/suggestions? I am attempting to use the custom uri scheme interception, but I don't think it's being intercepted to that activity.

    Here is the activity:
    [IntentFilter ( actions: new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, DataSchemes = new[] { "com.googleusercontent.apps.<clientId>", "urn:ietf:wg:oauth:2.0:oob","xamarin-auth" }, DataHosts = new[] { "localhost", "authorize", }, DataPaths = new[] {"/", "/oauth2redirect", "/oauthredirect" }, AutoVerify = true ) ]

    here is the Authenticator creation:
    Authenticator = new OAuth2Authenticator(c.ClientId,null,c.Scope,c.AuthUrl,c.RedirectUrl,c.AccessTokenUri,null,true); Authenticator.ShowErrors = false; Authenticator.AllowCancel = true;

            var intent =  Authenticator.GetUI(this);

    redirect uri is this: RedirectUrl = new Uri("com.googleusercontent.apps.<clientId>:/oauth2redirect"),

  • tbycidiottbycidiot Member

    Were you able to figure this out? Having the exact same problem. Thanks!

  • MattRobbMattRobb GBUniversity ✭✭

    I am having the same problem on IOS . And I am keen to resolve it; please help! I log on successfully but the redirect does not work! Just like AlexOwens above I am using "com.googleusercontent.apps.MyclientId:/oauth2redirect" as my redirect. I have confirmed that the redirect is correct in my Info.plist too. I can login correctly, then I get the message Safari cannot open the page because the address is invalid.

    I have done all the Reset Safari and delete its history suggestions which were suggested elsewhere. That had no effect.

    Please advise soonest.



  • MattRobbMattRobb GBUniversity ✭✭

    Resolved! Unbelievably after messing about with this for a couple of hours I have resolved the problem, by re-reading the Google Instructions.

    Basically you use 2 variants of the Redirect Uri:

    In your Xamarin code using the package Xamarin.Auth, you include :/oauth2redirect to your Redirect url (without doing that you will receive an error). Just as Xamarin suggests.

    Then in the info.plist You only use: "com.googleusercontent.apps.MyclientId" (without adding :/oauth2redirect). And it will work correctly.

    I have attached the piece of Google documentation which made the format of the URL clear.

  • SweeHengCheahSweeHengCheah USMember ✭✭

    How to implement this for Android?

  • EdwardLinaresEdwardLinares USMember ✭✭

    Same here, Android always after a successful authentication go to the google search page, why?

  • microwalesmicrowales Member
    edited April 2019

    If you are having issue with redirect in android customtab. use xamarin.auth for now.
    https : // github .com/xamarin/Xamarin.Auth/issues/275#issuecomment-423780272
    https : // forums.xamarin .com/discussion/100286/xamarin-auth-android-chrome-custom-tabs-doesnt-close-on-redirect
    (i cant post links yet so remove the space :wink: )
    Version 1.6.x works fine in android btw.

  • MeigstonMeigston USMember ✭✭

    @Klingu said:

    @BrunoPasquini.7813 said:
    I am trying to use "com.googleusercontent.apps.5**************"; as a redirect url but it can not be converted to an uri and use it in the OAuth2Authenticator.

    You should add ":/oauth2redirect" at the end of your redirectUrl. Like below ;-)


    Allmost there ;-)

    It works for me. Thank you.

  • juhi20juhi20 Member


  • TusharSTusharS Member

    Hi @MattRobb ,
    For Ios **
    **I am having below code -

    if (Device.RuntimePlatform == Device.iOS)
    var authenticator = new OAuth2Authenticator(
    clientId: clientId,
    clientSecret: string.Empty,
    scope: Constants.GoogleScope,
    authorizeUrl: new Uri(Constants.GoogleAuthorizeUrl),
    redirectUrl: new Uri(redirectUri),
    accessTokenUrl: new Uri(Constants.GoogleAccessTokenUrl),
    getUsernameAsync: null,
    isUsingNativeUI: true

                    authenticator.Completed += OnAuthCompleted;
                    authenticator.Error += OnAuthError;
                    //authenticator.IsLoadableRedirectUri = true;
                    AuthenticationState.Authenticator = authenticator;
                    var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();

    --redirectUri - com.googleusercontent.apps.ClientId:/oauth2redirect

    I have added in Info.plist "com.googleusercontent.apps.MyclientId" (without adding :/oauth2redirect).

    But in the last line i.e presenter.Login(authenticator); it is not presenting me the UI for gmail. Any suggestions from your side.

  • elisafragelisafrag Member ✭✭

    As a white label SEO company we use a Google API Client Library to handle your application's OAuth 2.0 flow, the client library performs many actions that the application would otherwise need to handle on its own. For example, it determines when the application can use or refresh stored access tokens as well as when the application must reacquire consent. The client library also generates correct redirect URLs and helps to implement redirect handlers that exchange authorization codes for access tokens.

Sign In or Register to comment.