npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@cambridge-pte/adonisjs6-ally-okta

v2.0.0

Published

Custom adonisjs6/ally provider for Okta.

Readme

AdonisJS 6 Ally Okta Provider

A custom OAuth2 provider for AdonisJS Ally that adds Okta authentication support.

Getting Started

Installation

Install the package using your preferred package manager:

npm install @cambridge-pte/adonisjs6-ally-okta
yarn add @cambridge-pte/adonisjs6-ally-okta
pnpm add @cambridge-pte/adonisjs6-ally-okta

Configuration

Configure the package by running:

node ace configure @cambridge-pte/adonisjs6-ally-okta

Environment Variables

Add the required environment variables to your .env file:

OKTA_DRIVER_CLIENT_ID=your_okta_client_id
OKTA_DRIVER_CLIENT_SECRET=your_okta_client_secret
OKTA_DRIVER_AUTHORIZE_URL=https://your-domain.okta.com/oauth2/default/v1/authorize
OKTA_DRIVER_USER_INFO_URL=https://your-domain.okta.com/oauth2/default/v1/userinfo
OKTA_DRIVER_TOKEN_URL=https://your-domain.okta.com/oauth2/default/v1/token
OKTA_DRIVER_RESPONSE_TYPE=code
OKTA_DRIVER_SCOPES=openid email profile

Ally Configuration

Update your config/ally.ts file to include the Okta provider:

import { defineConfig } from '@adonisjs/ally'
import { OktaDriverService } from '@cambridge-pte/adonisjs6-ally-okta'
import env from '#start/env'

const allyConfig = defineConfig({
  // ... other providers like github, google, etc

  okta: OktaDriverService({
    clientId: env.get('OKTA_DRIVER_CLIENT_ID'),
    clientSecret: env.get('OKTA_DRIVER_CLIENT_SECRET'),
    callbackUrl: `${env.get('APP_URL')}/auth/okta/callback`,
    authorizeUrl: env.get('OKTA_DRIVER_AUTHORIZE_URL'),
    accessTokenUrl: env.get('OKTA_DRIVER_TOKEN_URL'),
    userInfoUrl: env.get('OKTA_DRIVER_USER_INFO_URL'),
    scopes: env.get('OKTA_DRIVER_SCOPES'),
    responseType: env.get('OKTA_DRIVER_RESPONSE_TYPE'),
  }),
})

export default allyConfig

// TypeScript module augmentation for proper type inference
declare module '@adonisjs/ally/types' {
  interface SocialProviders extends InferSocialProviders<typeof allyConfig> {}
}

Usage

Basic Authentication Flow

Create routes for handling the OAuth flow:

// start/routes.ts
import router from '@adonisjs/core/services/router'

router.get('/okta/callback', '#controllers/oidc_controller.callback')

In your controller:

import type { HttpContext } from '@adonisjs/core/http'
import User from '#models/user'

// modify as needed
const API_TOKEN_EXPIRY = '1d'

export default class OIDCController {
  async callback({ ally, auth, response }: HttpContext) {
    const okta = ally.use('okta')

    if (okta.accessDenied()) {
      return response.badRequest({ error: 'Access was denied' })
    }

    if (okta.stateMisMatch()) {
      return response.badRequest({ error: 'Request expired. Retry again' })
    }

    if (okta.hasError()) {
      return response.badRequest({ error: okta.getError() })
    }

    try {
      const { token: accessToken } = await okta.accessToken()
      const { name: userName, email } = await okta.userFromToken(accessToken)
      const user = await User.updateOrCreate(
        {
          email,
        },
        {
          fullName: userName,
          email,
        }
      )

      const token = await auth.use('user').login(user, {
        expiresIn: API_TOKEN_EXPIRY,
      })

      return response.json({
        success: true,
        message: 'Authentication successful',
        data: {
          token,
          userName,
          email,
        },
      })
    } catch (error) {
      return response.status(500).json({
        success: false,
        error: error.message,
      })
    }
  }
}

Note: This example assumes you're handling the initial OAuth redirect from your frontend application or another service. The callback route processes the authorization code returned by Okta after user authentication.

Available Scopes

The provider supports the following Okta scopes:

  • openid - Required for OpenID Connect
  • email - Access to email address
  • profile - Access to profile information
  • address - Access to address information
  • phone - Access to phone number
  • offline_access - Refresh token support
  • groups - Access to group membership

User Object

The returned user object contains:

{
  id: string // Okta user ID (sub claim)
  name: string // Full name
  nickName: string // Display name
  email: string // Email address (from preferred_username)
  avatarUrl: string // Profile picture URL
  emailVerificationState: 'verified' | 'unverified'
  original: object // Raw response from Okta
}

TypeScript Support

This package includes full TypeScript support with proper type definitions for:

  • Configuration options
  • User object structure
  • Available scopes
  • Driver methods

Setting up TypeScript Support

The module augmentation should be added to your config/ally.ts file as shown above:

// In your config/ally.ts file
declare module '@adonisjs/ally/types' {
  interface SocialProviders extends InferSocialProviders<typeof allyConfig> {}
}

This enables full TypeScript intellisense for the Okta driver, allowing you to use:

// In your controllers
const okta = ally.use('okta') // Properly typed as OktaDriver
await okta.user() // Full method autocomplete and type safety

Importing Types

Import types when needed for configuration or custom implementations:

import type { OktaDriverConfig, OktaDriverScopes } from '@cambridge-pte/adonisjs6-ally-okta/types'

License

MIT License - see the LICENSE.md file for details.