Giter Club home page Giter Club logo

xamarin-forms-oauth's Introduction

Xamarin Forms app using Google OAuth

Xamarin Forms iOS Xamarin Forms Android

It's was a litte pain in the ass because one project must have two oAUth clients, one per each platform (Android/ iOS) because it's the way that Google works. All the oAuth providers works in the same way?

Xamarin Auth is a nuget package to work with oAuth in Xamarin and it does the hard work with the oAuth flow. This libray includes the OAuthLoginPresenter that works in both platforms (it's not required to add custom UI in each platform) and the OAuth2Authenticator that allows us to handle the proccess with the events Completed and Error.

To Remember

We have to manage the returnUrl of our OAuth2Authenticator in each platform, so in Android platform we have to use an activity interceptor that it's the place to setup the DataSchemes and DataPaths.

[IntentFilter(
        actions: new[] { Intent.ActionView },
        Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
        DataSchemes = new[]
                {
                    "com.mookiefumi.blacksabbath",
                    "com.googleusercontent.apps.[YOUR_CLIENT_ID]",
                    "urn:ietf:wg:oauth:2.0:oob"
                },
        DataPaths = new[] { "/oauth2redirect" },
        AutoVerify = true
)]

In iOS platform we have to add two Url Types in our Info.plist file (Advanced tab).

Hacks

In Android platform the OAuthLoginPresenter uses CustomTabs. It doesn't work well so we have to call StartActicity int our CustomUrlSchemeInterceptorActivity because the browser is not closing automatically.

new Task(() =>
{
    var intent = new Intent(ApplicationContext, typeof(MainActivity));
    intent.AddFlags(ActivityFlags.ClearTop);
    intent.AddFlags(ActivityFlags.SingleTop);
    StartActivity(intent);
}).Start();

In iOS platform works without any issues.

Summary/ Notes

Why always the Android platform have so many hacks or issues?

Links

Google Cloud Platform

Xamarin Auth

Google OpenId discover document

Google developers OAuth 2.0 Playground

OpenID Connect Playground

Mobile authentication with Xamarin.Auth and refresh tokens

xamarin-forms-oauth's People

Contributors

mookiefumi avatar

Stargazers

Sergio Navarro Pino avatar

Watchers

James Cloos avatar  avatar

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.