GithubHelp home page GithubHelp logo

andresguedes / trustly-android-navigation-example Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 350 KB

This is an implementation of Truslty JS integration, using Navigation Components

Kotlin 100.00%

trustly-android-navigation-example's Introduction

About this demo

This app demo has a propose to demonstrate how to implement the oauth authentication in Android apps, using Jitpack Navigation Components.

IMPORTANT:

Chrome Custom Tabs has no method to close itself, and this implementation is based on redirecting to previous Activity, by Intent flags, finishing the called Activity with registered scheme.

Introduction

These are some example how to implement a sign-in on OAuth flow to use Trustly JavaScript SDK. The code is using Kotlin language implementation.

CustomWebView

It is a simple custom view with a WebView inside, to open the transported url. In your custom web view you need to create a CustomTabIntent to open the url:

    private fun launchUrl(context: Context, url: String) {
        val customTabsIntent = CustomTabsIntent.Builder().build()
        customTabsIntent.launchUrl(context, Uri.parse(url))
    }

TrustlyRedirectActivity

When the application receive some action for redirect-navigation, or the name that you defined in urlScheme, it will call your target Activity with some flags, and reload it.

    Intent(this, MainActivity::class.java).apply {
        addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
    }.run { startActivity(this) }
    finish()

AndroidManifest

    <activity
    android:name=".TrustlyRedirectActivity"
    android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="redirect-navigation" />
            <data android:path="/second-fragment" />
        </intent-filter>
    </activity>

ProceedToChooseAccount

Finally, in order to support a smooth user experience when an OAuth login authorization is completed and the user returns to the Lightbox, call this function using some code like this:

    webView.loadUrl("javascript:window.Trustly.proceedToChooseAccount();")

trustly-android-navigation-example's People

Contributors

andresguedes avatar

Watchers

 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.