flutter_okta_sdk 1.0.0-dev.1

Flutter Android iOS

SDK to handle Okta Authentication

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.

Todos #

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

Android #

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

iOS #

setup signIn customSignIn singOut 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:
SettingValue
App NameMy Native App
Login redirect URIscom.mynativeapp:/
Grant Types AllowedAuthorization Code, Refresh Token

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

SettingWhere to Find
Client IDIn the applications list, or on the "General" tab of a specific application.
Org URLOn 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 #

TODO: (Need to publish this lib in pub .dev)

Add this to your package's pubspec.yaml file:

´´´ dependencies: flutter_okta_sdk: 1.0.0-dev.1 ´´´

You can install packages from the command line:

with Flutter:

flutter pub get

Now in your Dart code, you can use:

import 'package:flutter_okta_sdk/flutter_okta_sdk.dart';

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.

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(
      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 Response

Sample responses can be found [here](https://developer.okta.com/docs/reference/api/oidc/#response-properties-3

introspectIdToken #

Sample Response

Sample responses can be found here

introspectRefreshToken #

Introspect the id token.

Sample Response

Sample responses can be found here

refreshTokens #

Refreshes all tokens. Return the refreshed tokens.

1
likes
80
pub points
37%
popularity

Publisher

sonikro.com

SDK to handle Okta Authentication

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_okta_sdk