Okta Configuration
Configuration Details
Okta Configuration
Before integrating Auth Connect into your Ionic app, you’ll need to get Okta up and running.
For complete information on configuring Okta, consult the official documentation which includes tutorials on creating users and applications.
We recommend following the guide for Single Page Applications. This will enable your application to use the PKCE authentication flow and will work for both browser and app authentication.
Install Auth Connect
Run the following command to install the Auth Connect plugin. For the AUTH_URL_SCHEME
variable, use the globally unique App Id (ex: com.company.app
) you decided on when configuring the Azure AD app above.
Installation
If you have not already setup Ionic Enterprise in your app, follow the one-time setup steps.
Next, install the plugin:
- Capacitor
- Cordova
npm install @ionic-enterprise/auth
npx cap sync
ionic cordova plugin add capacitor-compat-plugin
ionic cordova plugin add @ionic-enterprise/auth --variable AUTH_URL_SCHEME=com.company.app
Configure Auth Connect
It's recommended to create an AuthenticationService
class that encapsulates Okta and Ionic Auth Connect’s login functionality.
Generate this class using the ionic generate
command:
_10ionic generate service services/authentication
Extend the IonicAuth
class, then configure all Okta details in the IonicAuthOptions
object:
_37import { IonicAuth, IonicAuthOptions } from '@ionic-enterprise/auth';_37_37export class AuthenticationService extends IonicAuth {_37_37constructor() {_37 const oktaConfig: IonicAuthOptions = {_37 // The auth provider._37 authConfig: 'okta',_37 // The platform which the app is running on_37 platform: 'cordova',_37 // client or application id for provider_37 clientID: 'FILL_IN',_37 // the discovery url for the provider_37 // OpenID configuration_37 discoveryUrl: 'FILL_IN',_37 // the URI to redirect to after log in_37 redirectUri: 'FILL_IN',_37 // requested scopes from provider_37 scope: 'FILL_IN',_37 // the audience, if applicable_37 audience: 'FILL_IN',_37 // the URL to redirect to after log out_37 logoutUrl: 'FILL_IN',_37 // The type of iOS webview to use. 'shared' will use a webview that can_37 // share session/cookies on iOS to provide SSO across multiple apps but_37 // will cause a prompt for the user which asks them to confirm they want_37 // to share site data with the app. 'private' uses a webview which will_37 // not prompt the user but will not be able to share session/cookie data_37 // either for true SSO across multiple apps._37 iosWebView: 'private',_37 // Use the newer PKCE Authentication Flow_37 webAuthFlow: 'PKCE'_37 };_37_37 super(oktaConfig);_37 }_37}
Some of these IonicAuthOptions
values are unique, and must be set based on your Okta details:
platform
: Use “cordova” or “capacitor” accordingly.clientID
: Your app’s Client ID, found under Applications -> [Your Application] -> General.redirectUri
: The URI to redirect to after the user has logged in. Use the same AUTH_URL_SCHEME variable value (App Id) from when the Auth Connect plugin was installed. Example: com.company.app://callback. Find this under Applications -> [Your Application] -> General.logoutUrl
: The URI to redirect to after the user has logged out. Example: com.company.app://login?logout=true. Find this under Applications -> [Your Application] -> General.
The discoveryUrl
formula is:
https://ORGANIZATION_DOMAIN.okta.com/.well-known/openid-configuration
Where ORGANIZATION_DOMAIN
is the domain you created when setting up your Okta account. You can find a reference to this under Applications -> [Your Application] -> Sign On -> OpenID Connect ID Token -> Issuer
What's Next?
Check out the full list of configuration options available, then implement the other steps in the Auth Connect workflow.