Giter Club home page Giter Club logo

okta-api-center's Introduction

Okta API Center

Overview

The Okta API Center gives developers tools to see how easily Okta's API Access Management (OAuth as a Service) capabilities integrate with leading API gateways and application proxies.

This project includes:

  1. Instructions for setting up various leading API gateways to use Okta as an authorization server
  2. Instructions for setting up Okta with users, groups, authorization policies, and custom scopes
  3. A sample Node.js application that will allow sample end-users to get access tokens, and pass those access tokens to protected endpoints in your API gateway

If you want to see what these flows can look like from an end-user perspective, you can check out the public demo site and video.

Okta is a standards-compliant OAuth 2.0 authorization server and a certified OpenID Provider.

Quick setup

  1. follow the step-by-step instructions to set up your Okta tenant with all of the objects that you need to generate access tokens with scopes
  2. use the sample application app.js to enable sample users to get access tokens (with scopes) from your Okta authorization server
  3. set up your API Gateway to validate access tokens issued by Okta
  4. test your setup by using the sample application to send requests with access tokens to your API gateway.

Prerequisites

  • An Okta tenant - If you don't already have an Okta tenant, you can sign up for a free-forever Okta developer edition.

  • Node.js - the test application for this setup runs on Node.

  • An API Gateway - if you want to test the API gateway piece of this setup, you'll need an API gateway. Okta will work with any gateway that supports an external OAuth provider; a list of gateways that have been proven out follows.

Gateways

Okta is a standards-compliant OAuth 2.0 authorization server and a certified OpenID Provider, so Okta will work with any API gateway or service that supports an external OAuth provider. As of today (July 2020), we have directly proven out compatibility with the following gateways (and reverse proxies):

  • Amazon API gateway
  • Apigee
  • Google Cloud Endpoints
  • Kong
  • Mulesoft
  • NGINX
  • Software AG
  • Tyk

Overview of setup

The overall setup has the following components:

  1. Set up your Okta tenant
  2. Set up the sample application (and test it)
  3. Set up your API (a mock API is available) and API Gateway
  4. Test the application -> API gateway connection

You may find it helpful to read the following overview before jumping in to the setup steps.

Overview of API access management & sample application

An API access management workflow typically includes the following components:

  • An API
  • An API gateway
  • An application
  • An OAuth authorization server
  • An identity provider

And, of course, a use-case to drive the configuration of all of those components.

This setup uses a simple use-case to illustrate how the overall flow works:

  • You are managing a "solar system" API and a viewing application.
  • You want to control access to the API so that only users with a silver-level subscription (scope) get access to a list of the planets, and only users with a gold-level subscription (scope) get access to a (partial) list of the moons.

With that use-case as context, the detailed setup instructions follow.

Set up your Okta tenant

To illustrate this use-case, you need to set up a number of different objects (users, groups, clients, policies, etc.) in your Okta tenant. Instructions for setting up your Okta tenant are here.

After you've set up your Okta tenant, come back here and move on to testing your setup against the test application.

Set up the test application

The test application allows your end-users to authenticate against your Okta tenant and get an access token (via the authorization code grant flow). The application can then send the access token to protected endpoints on your chosen API Gateway.

Prerequisites for the sample application

You'll need the following values from setting up your Okta tenant:

OKTA_TENANT

example: https://dev-399486.okta.com

ISSUER

example: https://dev-399486.okta.com/oauth2/default

this value will be `{{OKTA_TENANT}}/oauth2/default` unless you've set up a different authorization server in Okta.

CLIENT_ID

CLIENT_SECRET

Setup for sample application

  1. Download this repo:

git clone https://github.com/tom-smith-okta/okta-api-center

  1. Change to the application directory:

cd okta-api-center

  1. Install the node modules:

npm install

  1. This app uses the dotenv npm package to manage configuration settings.

Copy the .env_example file to a file called

.env

Open the .env file and update the settings for your environment. If you've followed all of the instructions so far and accepted all of the defaults, then you'll only need to update the following values:

OKTA_TENANT

ISSUER

CLIENT_ID

CLIENT_SECRET

If you're using Tyk as your gateway, change GATEWAY_IS_TYK to true.

There is a sample value for GATEWAY_URI that you can ignore for now; you'll update that after you set up your API Gateway.

Save the .env file.

Launch and test the application

With your settings updated in the .env file, go ahead and launch the application:

node app.js

Open a web browser and go to

http://localhost:8080

The happy path is to click the authenticate button in the "silver access" box and authenticate as carl.sagan. If all goes well, you will see a decoded access token in the access token box.

Similarly, if you click the authenticate button in the "gold access" box and authenticate as jodie.foster, you will see a decoded access token in the access token box.

The "raw" access token is available in the developer console if you want to inspect it.

Note: a "real world" web application that is using the authorization code grant flow would not typically send the access token to the browser, but would rather keep it server-side. We're sending it back to the browser here for demo purposes.

Note: if you authenticate as carl.sagan when you click on the authenticate button in the "gold access" box, you will successfully authenticate (get an Okta session) but you will not get an access token because the requested scopes do not line up with the policy you've set up in the authorization server.

Note: if you've followed the default Okta setup instructions, your default access policy will still be active in your tenant. The default access policy actually allows any user to be granted any scope (as long as the scope is requested in the authorization request). If you want to see if the authorization policies are "really" working, then just make the default policy for the authorization server inactive.

If you click on the "show me" links now, they won't work, because we haven't set up the gateway_uri in our app yet. That's the next step.

Set up your API Gateway + API

Each API Gateway accommodates external OAuth providers slightly differently. Follow the instructions in the 'gateways' folder of this repo for the gateway that you are using. Instructions are available for the following gateways:

  • Apigee
  • Amazon API gateway
  • Kong
  • Mulesoft
  • Software AG
  • Tyk

Please note that I have provided a very simple solar system API here: https://okta-solar-system.herokuapp.com

This API echoes a list (json object) of the planets: https://okta-solar-system.herokuapp.com/planets

And a (partial!) list of the moons: https://okta-solar-system.herokuapp.com//moons

For demo purposes, the API is wide open. In a real-world use-case you would of course lock down the API so that it could be accessed only through your gateway.

When you have finished setting up your API Gateway, come back to this doc to test your application and access tokens.

You will need the URI of your gateway for the next step.

Test your application and access tokens

Now that you have set up your API Gateway, you should have a gateway uri. Enter that value in the .env file and restart the Node application.

Now, after you authenticate, you should be able to click on one of the "show me" buttons and get a list of the moons and/or planets, depending on the scopes in your access token.

okta-api-center's People

Contributors

coopr avatar noinarisak avatar sedkis avatar stevenmccullar-okta avatar tom-smith-okta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

okta-api-center's Issues

Doesn't this require the "API Access Management" add-on package?

The tutorial involves setting up custom authorization servers, but last I checked that's not a feature included by default in a lot of Okta subscriptions. It's part of the "API Access Management" package (see the banner at the top here: https://developer.okta.com/docs/concepts/auth-servers/)

If this is indeed the case, please add a warning or disclaimer to the guide. As a new user, it's very frustrating to spending hours looking for buttons that don't exist in the Okta UI.

If there is a way to do this tutorial (or at least to the extent of not implementing scoped access) without needing to buy extra add-on products, please let me know.

schema violation (route_id: unknown field)

HI, I am following instructions given in readme. When I reach to step to add plugin to route using given command

curl -i -X POST \
  --url http://localhost:8001/services/solar-system/plugins/ \
  --data 'name=openid-connect' \
  --data 'route_id=85533238-8e8f-453c-ab9c-eaca583c5685' \
  --data 'config.issuer=https://dev-840080.oktapreview.com/oauth2/axxn3xxxxxxxftl0h7' \
  --data 'config.client_id=0oxxxxxxxxxxxx40h7' \
  --data 'config.ssl_verify=false' \
  --data 'config.cache_ttl=60' \
  --data 'config.scopes_required=http://myapp.com/scp/silver' \
  --data 'config.scopes_claim=scp'

It throws following exception:

HTTP/1.1 400 Bad Request
Date: Wed, 21 Aug 2019 05:20:13 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Access-Control-Allow-Origin: *
X-Kong-Admin-Request-ID: ZEsssptj2RKW1h2jfsZBOLUKFyDJY7M8
Server: kong/0.36-enterprise-edition
Content-Length: 129

{"message":"schema violation (route_id: unknown field)","name":"schema violation","fields":{"route_id":"unknown field"},"code":2}

I am suspecting something has changed in recent kong version. If anyone have an idea, what is going wrong, please guide me>

Programmatic access?

I understand this obtains an access token from the OIDC handshake, which is then used as a bearer token to query the API.

If I wanted to query the API directly programmatically, not from web app, but from a batch job for example, how can I obtain an access token in that case?

thanks

Cannot find module 'request'

Got the following errors when trying to build the app:

Error: Cannot find module 'request'
Require stack:
- C:\okta-api-center-master\routes.js
- C:\okta-api-center-master\app.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\okta-api-center-master\routes.js:8:15)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\okta-api-center-master\\routes.js',
    'C:\\okta-api-center-master\\app.js'
  ]
} 

Was able to work around this by adding the following dependency to packages.json:

    "request": "^2.88.2"

Check group

Hello, our API Gateway is working with OKTA, but we do not know where can we check OKTA GROUPS. For example if the user has "group1" they will authorize, if not have group unauthorized.

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.