Skip to content

Telcrome/samples-js-angular

 
 

Repository files navigation

Angular Sample Applications for Okta

This repository contains several sample applications that demonstrate various Okta use-cases in your Angular application.

Each sample makes use of the Okta Angular Library.

If you haven't done so already, register for a free account at developer.okta.com. Select Create Free Account and fill in the forms to complete the registration process. Once you are done and logged in, you will see your Okta Developer Console.

Tip: You can also create an account using the Okta CLI and okta register. To create an app, run okta apps create and use the settings below.

Register your application by selecting Applications > Add Application. On the next screen, choose Single Page App and click Next.

On the following screen, edit the application settings. For these sample applications we are using port number 8080. Configure your app as follows:

  • Base URI: http://localhost:8080
  • Login redirect URI: http://localhost:8080/login/callback
  • Logout redirect URI: http://localhost:8080

Once you have completed the form, you will be given a client ID. You will also need the issuer value for your Okta org.

The issuer is the URL of the authorization server that will perform authentication. All Developer Accounts have a "default" authorization server. The issuer is a combination of your Org URL (found in the upper right of the console home page) and /oauth2/default. For example, https://dev-133337.okta.com/oauth2/default.

These values must exist as environment variables. They can be exported in the shell, or saved in a file named testenv, located in the same directory as this README. See dotenv for more details on this file format.

ISSUER=https://yourOktaDomain.com/oauth2/default
CLIENT_ID=123xxxxx123

Please find the sample that fits your use-case from the table below.

Sample Description
Okta-Hosted Login An Angular application that will redirect the user to the Okta-Hosted login page for authentication. The user is redirected back to the Angular application after authenticating.
Custom Login Page An Angular application that uses the Okta Sign-In Widget within the Angular application to authenticate the user.

Running the resource server

The samples include a page which accesses a protected resource (messages). To start the sample resource server:

npm run resource-server

Running the tests

In addition to the other environment vars, you will need credentials for a test user. Add the values for your Okta org and user in a testenv file.

ISSUER=https://yourOktaDomain.com/oauth2/default
CLIENT_ID=123xxxxx123
USERNAME=testuser@email.com
PASSWORD=testpass

With these variables set, you should be able to run npm test and bask in the glory of passing tests.

Packages

No packages published

Languages

  • TypeScript 56.7%
  • JavaScript 21.5%
  • HTML 18.9%
  • Shell 2.5%
  • Other 0.4%