Code Monkey home page Code Monkey logo

flutter-okta-sdk's Introduction

Flutter Okta SDK

The Flutter Okta SDK library makes it easy to add authentication to your Flutter app. This library is a wrapper around Okta OIDC Android and Okta OIDC iOS.

This library follows the current best practice for native apps using:

This library also exposes APIs to interact with Authentication API directly to implement native UI for authentication.

Sample

You can check how to use this plugin in this sample Futter Okta Sample

Todos

This library is under construction. These are the next steps:

Android

createConfig signIn customSignIn signOut authenticate isAuthenticated getAccessToken getIdToken getUser revokeAccessToken revokeIdToken revokeRefreshToken clearTokens introspectAccessToken introspectIdToken introspectRefreshToken refreshTokens

iOS

setup signIn customSignIn signOut getAuthClient authenticate isAuthenticated getAccessToken getIdToken getUser getUserFromIdToken revokeAccessToken revokeIdToken revokeRefreshToken clearTokens introspectAccessToken introspectIdToken introspectRefreshToken refreshTokens

web

setup signIn customSignIn singOut getAuthClient authenticate isAuthenticated getAccessToken getIdToken getUser getUserFromIdToken revokeAccessToken revokeIdToken revokeRefreshToken clearTokens introspectAccessToken introspectIdToken introspectRefreshToken refreshTokens

Prerequisites

Add an OpenID Connect Client in Okta

In Okta, applications are OpenID Connect clients that can use Okta Authorization servers to authenticate users. Your Okta Org already has a default authorization server, so you just need to create an OIDC client that will use it.

  • Log into the Okta Developer Dashboard, click Applications then Add Application.
  • Choose Native as the platform, then submit the form the default values, which should look similar to this:
Setting Value
App Name My Native App
Login redirect URIs com.mynativeapp:/
Grant Types Allowed Authorization Code, Refresh Token

After you have created the application there are two more values you will need to gather:

Setting Where to Find
Client ID In the applications list, or on the "General" tab of a specific application.
Org URL On the home screen of the developer dashboard, in the upper right.

Note: As with any Okta application, make sure you assign Users or Groups to the OpenID Connect Client. Otherwise, no one can use it.

These values will be used in your Flutter application to setup the OpenID Connect flow with Okta.

Getting started

You can check the pub.dev to know how to install this plugin. Flutter Okta SDK.

Setup Android

For Android, there is one steps that you must take:

  1. Add a redirect scheme to your project.

Add redirect scheme

  1. Defining a redirect scheme to capture the authorization redirect. In android/app/build.gradle, under android -> defaultConfig, add:
  manifestPlaceholders = [
    appAuthRedirectScheme: 'com.sampleapplication'
  ]
  1. Make sure your minSdkVersion is 19.
  2. Create a proguard-rules.pro file inside the android/app folder and add the following rule
-ignorewarnings
-keep class com.okta.oidc.** { *; }

  1. Add a couple of rules to the buildTypes/release block inside the app/build.gradle file

    buildTypes { release { useProguard true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.release } }

Setup iOS

TODO: (Need to do the iOS bridge)

Usage

You will need the values from the OIDC client that you created in the previous step to set up. You will also need to know your Okta Org URL, which you can see on the home page of the Okta Developer console.

Before calling any other method, it is important that you call createConfig to set up the configuration properly on the native modules.

import 'package:flutter_okta_sdk/flutter_okta_sdk.dart';
import 'package:flutter_okta_sdk/BaseRequest.dart';

var oktaSdk = OktaSDK();
var oktaBaseRequest = BaseRequest(
      issuer: OKTA_ISSUER_URL,
      clientId: OKTA_CLIENT_ID,
      discoveryUrl: OKTA_DISCOVERY_URL,
      endSessionRedirectUri: OKTA_LOGOUT_REDIRECT_URI,
      redirectUrl: OKTA_REDIRECT_URI,
      scopes: ['openid', 'profile', 'email', 'offline_access']);

await oktaSdk.createConfig(oktaBaseRequest);

createConfig

This method will create a configured client on the native modules.

Note: requireHardwareBackedKeyStore is a configurable setting only on android devices. If you're a developer testing on android emulators, set this field to false.

signIn

This method will redirect to okta´s sign in page, and will return when to the app if the user cancels the request or has error or the login was made. The return object will have a parameter resolve_type that can assume the following values: authorized, signed_out, cancelled

if (oktaSdk.isInitialized == false) {
  await this.createConfig();
}
var result = await oktaSdk.signIn();

signOut

Clear the browser session and clear the app session (stored tokens) in memory. Fires an event once a user successfully logs out The return object will have a parameter resolve_type that can assume the following values: authorized, signed_out, cancelled

  if (oktaSdk.isInitialized == false) {
    await this.createConfig();
  }
  var result = await oktaSdk.signOut();

isAuthenticated

Return true if there is a valid access token or ID token. Otherwise false

getAccessToken

This method returns the access token as a string. If no access token is available (either does not exist, or expired), an error will be thrown.

getIdToken

This method returns the identity token as a string. If no identity token is available an error will be thrown.

getUser

Returns the most up-to-date user claims from the OpenID Connect /userinfo endpoint.

revokeAccessToken

Revoke the access token to make it inactive. Resolves true if access token has been successfully revoked.

revokeIdToken

Revoke the identity token to make it inactive. Resolves true if id token has been successfully revoked.

revokeRefreshToken

Revoke the refresh token to make it inactive. Resolves true if refresh token has been successfully revoked.

clearTokens

Removes all tokens from local storage. Resolves true if tokens were successfully cleared.

introspectAccessToken

Introspect the access token.

Sample responses can be found here

introspectIdToken

Introspect the id token.

Sample responses can be found here

introspectRefreshToken

Introspect the refresh token.

Sample responses can be found here

refreshTokens

Refreshes all tokens. Return the refreshed tokens.

flutter-okta-sdk's People

Contributors

amr-eniou-3r avatar chaitanya-bhagavan avatar domesticmouse avatar j-dk avatar jsorgensen-lendio avatar markteffeteller-okta avatar marktefftech avatar perdiga avatar sonikro avatar stevenbarash avatar tal-nir avatar

Stargazers

 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

flutter-okta-sdk's Issues

IOS Error

flutter: MissingPluginException(No implementation found for method createConfig on channel com.sonikro.flutter_okta_sdk)

App crashes when cancel the login page

Hi:
After imported the package, I am able to see the okta login page, as the plugin (for example the login function) has no return value, so the app doesn't know if the page returns any error.
This causes our app to crash.
Do you have any plan to fix this?
Or am I using it incorrectly?
Thanks

Keep users signed in with refresh token

Hi,

I'm trying to set up a mobile app where users only need to sign in once. After that, every time the splash screen loads, the client calls oktaSdk.refreshTokens(), which allows us to get a new access token for the resource server. On the Okta portal, I have Authorization Code and Refresh Token checked off for allowed grant types.

However, if I login and then restart the app and wait for approximately 2 hours, and then call oktaSdk.refreshTokens(), I get the following error: PlatformException(RefreshToken_Error, User not logged in, cannot refresh, Optional(flutter_okta_sdk.FlutterOktaError(message: "User not logged in, cannot refresh")), null). From this error, I get the impression that Okta is automatically signing out users after some inactivity (even though we have already written our tokens to secureStorage)?

I'm wondering:

  1. Is it possible with this package to allow users to only sign in once and only have to sign back in if they click to sign out, similar to how most mobile apps work like Facebook, Instagram, etc?
  2. If it is possible, how would the flow look like to make this possible?

Also, regardless of your response, this package has honestly been a game changer in speeding up development for my mobile app. Thanks so much for creating this plug in!

Web Implementation

Hi guys,

This plugin saved me from a lot of hassle of native implementation on Native android and iOS. Thanks to you guys for that.

Just Creating this (more of a thread than an issue) for Web implementation. As we want to do this on the web as well.

  1. When can we expect the web version?
  2. If not coming soon, then what can we do to implement that on our end? Some info, like where to start and all?

Regards

Issuer is missing

Hello,

You always sending the requests without issue
Could you add it?

data class OktaRequestParameters(
        var issuer: String = "default",
        var clientId: String,
        var redirectUri: String,
        var endSessionRedirectUri: String,
        var discoveryUri: String,
        var scopes: ArrayList<String>,
        var userAgentTemplate: String = "",
        var requireHardwareBackedKeyStore: Boolean = false
)

Android Release Build issue

Hey there

I've been using your library for almost 3-4 weeks and everything was working perfectly, the login/logout flow works perfectly during development, then I created a android apk release build for for testing and I noticed the webview flow stops working, the web browser don't open and I get a Platform exception, the strange part is everything works in a release mode. Have you tried to create a release build before for your sample app?

Regards and thanks!

Getting different JWT token for Android and iOS from Okta OIDC PKCE

Using this library for Android and iOS but getting different type of JWT token. When decoded, we found following difference.
Because of this difference token generated by iOS App is getting authenticated by backend server but token generated by Android app is getting rejected as invalid token.

Token generated by iOS looks like below. It contains "iss" ending with oauth2/default and aud as api://default.

{
  "ver": 1,
  "jti": "AT.Mbk7V5Sp1hNRzpHA4JKBoF9dniS4AO_WBPSUgNqJ4Pk",
  "iss": "https://org-dev.oktapreview.com/oauth2/default",
  "aud": "api://default",
  "iat": 1650342083,
  "exp": 1650345683,
  "cid": "0oa2gwdzyqm1DJAE41d7",
  "uid": "00u2icm9xhoYA6wVx1d7",
  "scp": [
    "email",
    "openid",
    "profile"
       ],
  "auth_time": 1650342081,
  "sub": "[email protected]"
}

But in case of Android, "iss" is just "https://org-dev.oktapreview.com" and aud is also "https://org-dev.oktapreview.com"

{
  "ver": 1,
  "jti": "AT.VMgUDc-wJnEXTx4n5I-QyKTI0yMGTqBWw8HA9FE6EPY",
  "iss": "https://org-dev.oktapreview.com",
  "aud": "https://org-dev.oktapreview.com",
  "sub": "[email protected]",
  "iat": 1649419357,
  "exp": 1649422957,
  "cid": "0oa2gwdzyqm1DJAE41d7",
  "uid": "00u2jz1wtzyVc1b0c1d7",
  "scp": [
    "openid",
    "profile",
    "email"
  ],
  "auth_time": 1649419354
}

LOOKING FOR MAINTAINERS

Me and @Perdiga are the creators of this package, however, we are not working with Flutter anymore, but we believe in the future of this package.

If you're working with flutter, and using this library, please consider becoming a Maintainer.

Please talk to me or @Perdiga if you're interested.

Thanks a lot

I gor URI Error

No uri registered to handle redirect or multiple applications registered when I test to use

Null Safety

Is there a timeline on this getting migrated to null safety?

License file

Could you please update the LICENSE file with correct licence and terms.

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.