Redirect URL for google oauth?

CodyRousseauCodyRousseau USUniversity ✭✭

Hello,

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

https://github.com/xamarin/xamarin-forms-samples/blob/master/WebServices/OAuthNativeFlow/OAuthNativeFlow/Constants.cs

and that does not work. Any ideas?

Thanks!

Tagged:

Answers

  • RobStellerRobSteller USMember ✭✭

    Were you able to figure this out?

  • CodyRousseauCodyRousseau USUniversity ✭✭

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

    https://auth0.com/

  • RobStellerRobSteller USMember ✭✭

    Thanks!

  • 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 ;-)

    "com.googleusercontent.apps.5-a-long-identifier-88:/oauth2redirect"

    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);
        StartActivity(intent);
    

    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.

    Thanks

    Matt

  • 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?

Sign In or Register to comment.