user3471528
user3471528

Reputation: 3053

Google authentication using Xamarin.Auth

I'm developing an application using Xamarin.Android.

I need to enable login with Facebook and Google and I choose to use the Xamarin.Auth component. I got it work with facebook but I have some issue with Google.

This is my code:

        var auth = new OAuth2Authenticator (
            clientId: "myId.apps.googleusercontent.com",
            clientSecret: "mysecred",
            scope: "openid",
            authorizeUrl: new Uri ("https://accounts.google.com/o/oauth2/auth"),
            redirectUrl: new Uri ("myredirect:oob"),
            accessTokenUrl: new Uri ("https://accounts.google.com/o/oauth2/token"),
            getUsernameAsync: null
        ); 

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

        auth.Completed += (sender, e) => {
            Console.WriteLine (e.IsAuthenticated);
        };

Is this way the Google Activity is displayed, and I can insert my Username and password. But when I click the google login button I get a message like this:

google auth please copy this code switch to your application and paste it there [code]

What I have to do with that code? I just need to get the user name/lastname/email/id.

Thanks a lot!

Upvotes: 1

Views: 4858

Answers (1)

Suchith
Suchith

Reputation: 1527

Bellow steps worked for me.

1.register in google developer console as webapplication instead of installed application(android)* provide the redirect url with valid url ("http://abcd.com/xyz.aspx") same should be used in the application code.

2.on authentication complete it will return access_token

3.by using the access_token make the REST request to get user complete information (https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + accessTokenValue + “.)

4.Deserialize the json response to get information in object.

check the source code :http://appliedcodelog.blogspot.in/2015/08/login-by-google-account-integration-for.html

Upvotes: 3

Related Questions