Xamarin Auth and TODOAWS example: some troubles...

Hi, to understand how to work xamarin.auth module, I'm usig TODOAWSAuth example. I update the Xamarin.Auth module to 1.4.1 but I'm not able to authenticate because I've a warning abount Http(s) schema and the native page go to redirecturl without close the page.
I change the code to:

var authenticator = new OAuth2Authenticator(
Constants.ClientId,
Constants.ClientSecret,
Constants.Scope,
new Uri(Constants.AuthorizeUrl),
new Uri(Constants.RedirectUrl),
new Uri(Constants.AccessTokenUrl),
null,
true);

and constants:

// These values do not need changing
//https://www.googleapis.com/auth/userinfo.email
public static string Scope = "https://www.googleapis.com/auth/userinfo.email";
public static string AuthorizeUrl = "https://accounts.google.com/o/oauth2/auth";
public static string AccessTokenUrl = "https://accounts.google.com/o/oauth2/token";
public static string UserInfoUrl = "https://www.googleapis.com/oauth2/v2/userinfo";

    // Set this property to the location the user will be redirected too after successfully authenticating
    //https://www.googleapis.com/plus/v1/people/me -- https://www.googleapis.com/auth/userinfo.email
    //urn:ietf:wg:oauth:2.0:oob:auto
    public static string RedirectUrl = "http://www.redconsulting.it";

and into IOS solution:

public void Login(Authenticator authenticator)
{
authenticator.Completed += AuthenticatorCompleted;

        rootViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;

        UIKit.UIViewController intent = (UIKit.UIViewController)authenticator.GetUI();

        rootViewController.PresentViewController(intent, true, null);

    }

Questions:

  • how to remove the http(s) schema warning?
  • how to clear the autentication or capture the refresh token so I can reauthenticate?
  • Is ok that type of redirectURL?

Posts

  • moljacmoljac HRBeta ✭✭✭

    http schema warning is for users that do not understand how CustomTabs and SFSafariViewController work.
    It is there so users would not loose their precious time with NativeUI (CustomTabs and SFSafariViewController) and http/https schemes.

    Is ok that type of redirectURL?

    NOPE. Google did provide you custom scheme used for that.

    Check those samples (I'm working on them)

    https://github.com/moljac/Xamarin.Auth.Samples.NugetReferences

    And go to Xamarin community slack team, there are people that have successfully implemented google login (including myself) and will be able to help you in real time.

  • biaparbiapar ITMember ✭✭
    edited April 27

    Thanks for your reply.
    I see that you use redirectUrl: new Uri("xamarin-auth://localhost") as RedirectUrl. Do it work?
    Could you explain better what you mean "http schema warning is for users that do not understand how CustomTabs and SFSafariViewController work"?
    Your Evolve16Labs is a very good example.

  • biaparbiapar ITMember ✭✭

    My code Xamarin Form works with Facebook Auth with native browser disabled. The problem is only for Google.

  • moljacmoljac HRBeta ✭✭✭

    I see that you use redirectUrl: new Uri("xamarin-auth://localhost") as RedirectUrl. Do it work?

    Yes. This one is for Fitbit. Fitbit lets you define redirect-url AKA callback. Google will generate custom-sheme for you based on Android Package Id and iOS BundleID which you were supposed to register when you have created Credentials on google console (portal).

    Could you explain better what you mean "http schema warning is for users that do not understand how CustomTabs and SFSafariViewController work"?

    Custom [Chrome] Tabs and SFSafariViewController are actually Chrome and Safari browsers and user is sending (requesting) urls with those "external" OS native, system browsers not your WebView in your app. When redirect-url is sent back something loads this url based on scheme. Something (some app) does register scheme app can handle in the system (OS) and guess who registers http[s]? yes. Browser. System Browser. OK. in 99.999999999%. It might be possible (iOS more less-likely than Android) to say "NO my app will handle all http uris", but this is not very good and for sure not default in Android and iOS.
    So, user must define some schema for redirect and register it in Android with Activity with IntentFilter and in iOS in Info.plist. Read about App Linking, Deep Linking etc...

    Your Evolve16Labs is a very good example.

    Thanks. I'm glad it helped.

    My code Xamarin Form works with Facebook Auth with native browser disabled.

    Yes. FB did not impose those restrictions, but I can recall they announced it too. So, read a little a bout it. You will need this concept in the future for sure.

    The problem is only for Google.

    joke(){ Yes. Google is always the problem }

    No it is not. Get your package id/bundle id and use it as custom scheme - check my samples.
    Yes seems like google allows few more custom schemes, but I did not have time to test them. You are 10+ person that I am explaining this either here or via github issues or community slack.

    The google's problem is that info I gave you here is scattered in 3-4 docs and not always explicitly written.

  • biaparbiapar ITMember ✭✭

    I'll retry with Google. In the app I've use FB auth for the first stage and xamarin.auth lib works very good and the accountstore is a good help.

  • moljacmoljac HRBeta ✭✭✭

    @biapar I'm working on adding FB samples with new API (Native UI), but 1st I'll add docs and merge into master

  • biaparbiapar ITMember ✭✭

    Well...I'm working with FB graph API in Xamarin Form. Do you want some help?

  • RamonNavarroRamonNavarro USMember

    @biapar can you give me example for FB NativeUI using xamarin.auth?

Sign In or Register to comment.