Coder Social home page Coder Social logo

oauthtwodemo.xforms's Introduction

A simple demo of Xamarin.Auth in Xamarin.Forms

This demo does not cover pulling back any profile data (or any other data) from your given auth provider's API (Facebook, Instagram, Twitter, Google, etc, etc, etc), but it will get you authenticated. After successful authentication, it's up to you to make subsequent calls against your chosen API with the auth token you receive.

Edit the App.cs class in the core project:

You'll need to edit the following in the App.cs in order to get the sample working with your OAuth provider:

_Instance.OAuthSettings = 
    new OAuthSettings (
        clientId: "",       // your OAuth2 client id 
        scope: "",          // The scopes for the particular API you're accessing. The format for this will vary by API.
        authorizeUrl: "",   // the auth URL for the service
        redirectUrl: "");   // the redirect URL for the service
        
        // If you'd like to know more about how to integrate with an OAuth provider, 
        // I personally like the Instagram API docs: http://instagram.com/developer/authentication/

What you get:

Xamarin.Auth with Xamarin.Forms iOS example Xamarin.Auth with Xamarin.Forms Android example

oauthtwodemo.xforms's People

Contributors

jacksierkstra avatar jsauve avatar jsauvexamarin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

oauthtwodemo.xforms's Issues

08-13 12:15:51.419 E/mono ( 1516): System.NullReferenceException: Object reference not set to an instance of an object.

When I attempt to run, I get this error:

An unhandled exception occured.

08-13 12:15:51.419 E/mono    ( 1516): 
08-13 12:15:51.419 E/mono    ( 1516): Unhandled Exception:
08-13 12:15:51.419 E/mono    ( 1516): System.NullReferenceException: Object reference not set to an instance of an object.
08-13 12:15:51.419 E/mono    ( 1516):   at (wrapper dynamic-method) System.Object:841dfca9-313d-4d04-b6fc-473c386af2df (intptr,intptr,bool,int,int,int,int)
08-13 12:15:51.419 E/mono    ( 1516):   at (wrapper native-to-managed) System.Object:841dfca9-313d-4d04-b6fc-473c386af2df (intptr,intptr,int,int,int,int,int)
In mgmain JNI_OnLoad
08-13 12:15:51.419 E/mono-rt ( 1516): [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object.
08-13 12:15:51.419 E/mono-rt ( 1516):   at (wrapper dynamic-method) System.Object:841dfca9-313d-4d04-b6fc-473c386af2df (intptr,intptr,bool,int,int,int,int)
08-13 12:15:51.419 E/mono-rt ( 1516):   at (wrapper native-to-managed) System.Object:841dfca9-313d-4d04-b6fc-473c386af2df (intptr,intptr,int,int,int,int,int)

Do you have any suggestions? TIA.

UPDATE:

This is the line where it is throwing the exception:

            var auth = new OAuth2Authenticator (
                clientId: App.Instance.OAuthSettings.ClientId, // your OAuth2 client id
                scope: App.Instance.OAuthSettings.Scope, // The scopes for the particular API you're accessing. The format for this will vary by API.
                authorizeUrl: new Uri (App.Instance.OAuthSettings.AuthorizeUrl), // the auth URL for the service
                redirectUrl: new Uri (App.Instance.OAuthSettings.RedirectUrl)); // the redirect URL for the service

Android.Views.WindowManagerBadTokenException: Exception of type 'Android.Views.WindowManagerBadTokenException' was thrown

Hi,
I used your code for my app but when I invoke an action in my android page renderer I get the above error. This is my code:

protected override void OnElementChanged(ElementChangedEventArgs e)
{
base.OnElementChanged(e);

        var activity = this.Context as Activity;

        var auth = new OAuth2Authenticator(
            clientId: App.GoogleApiClientId,
            clientSecret: App.GoogleApiClientSecret,
            scope: "email",
            authorizeUrl: new Uri(App.GoogleApiAuthorizeUrl),
            redirectUrl: new Uri(App.GoogleApiRedirectUrl2),
            accessTokenUrl: new Uri(App.GoogleApiAccessTokenUrl),
            getUsernameAsync: null
        );

        auth.Title = App.GetTextFromKey("Login");
        auth.AllowCancel = false;

        auth.Completed += (sender, eventArgs) =>
        {
            if (eventArgs.IsAuthenticated)
            {
                string code = "";
                eventArgs.Account.Properties.TryGetValue("access_token", out code);
                Console.WriteLine("ac: " + code);

                App.GoogleApiAccesToken = code;

                eventArgs.Account.Properties.TryGetValue("refresh_token", out code);
                Console.WriteLine("rc: " + code);

                NavHelper.Nav.NavigateToValidationPageAction.Invoke();
            }
        };

        activity.StartActivity(auth.GetUI(activity));
    }

public Action NavigateToValidationPageAction
{
get
{
return new Action(() =>
{
App.LoginOk = true;
NavPage.Navigation.PopModalAsync();
}
});
}
}

Doesn't seem to work right with Facebook.

Documented multiple places.

xamarin/Xamarin.Auth#70
http://forums.xamarin.com/discussion/25183/xamarin-forms-xamarin-auth-and-facebook?new=1
http://www.joesauve.com/using-xamarin-auth-with-xamarin-forms/

It will authenticate, but following that you only get a white screen with the red text mentioned in the other posts.

It's worth noting that the Android app works slightly better. For some odd reason you have to login to FB twice but on the second time it will properly redirect to the Profile page.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.