Integrate a JavaScript application¶
Follow the steps given below to authenticate users to a sample JavaScript service provider with OpenID Connect.
Prerequisites¶
Only customer users can log in to applications. Create a user account if you don't already have one.
Add CORS configurations¶
To add CORS configurations:
-
Open the
deployment.toml
file found in the<IS-Home>/repository/conf/
directory, and add the following configuration.[cors] allowed_origins = [ "https://localhost:3000" ] supported_methods = [ "GET", "POST", "HEAD", "OPTIONS", "PUT", "PATCH", "HEAD", "DELETE", "PATCH" ]
-
Restart the MWARE IAM to make the changes effective.
Info
For more information on CORS configurations, refer how to configure CORS during deployment.
Configure a service provider¶
- On the MWARE IAM management console (
https://<IS_HOST>:<PORT>/carbon
) go to Main > Identity > Service Providers. - Click Add and enter a Service Provider Name.
- Click Register to complete the registration.
- Expand Inbound Authentication Configuration > OAuth/OpenID Connect Configuration and click Configure.
-
Enter the Callback URL as
https://localhost:3000
.Note
The Callback URL is the exact location in the service provider's application to which an access token will be sent. This URL should be the landing page to which the user is redirected after successful authentication.
-
Click Add to complete the configuration.
Note
Make a note of the OAuth Client Key and OAuth Client Secret that appear, as they will be used to configure the sample application.
Download the sample¶
Download the latest release of the sample JavaScript application.
Configure the sample¶
- Open the
index.html
file located at the root of the project. -
Scroll down to the
<script>
tag at the end of the body tag and findauthConfig
object and change the configurations with the relevant values.-
clientID - Add the client id of the registered application. The client ID can be copied from Inbound Authentication Configuration > OAuth/OpenID Connect Configuration section of your service provider.
-
serverOrigin -
https://localhost:9443
-
scope - The list of OIDC scopes that are used for requesting user information. The
openid
and theprofile
scopes are mandatory to get the ID token. You can add other OIDC scopes such asemail
.
const authConfig = { clientID: <client_ID>, signInRedirectURL: "https://localhost:3000", baseUrl: "https://localhost:9443", scope: [ "profile" ] };
-
Run the sample¶
Run the following command at the root of the project to start up the sample application. The app will be accessible at https://localhost:3000
.
npm install && npm start
Log in to MWARE IAM management console using your user account credentials.
Top