Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed naming convention + updated package.json #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "adonis-ally-azure-ad",
"version": "0.3.0",
"description": "Azure AD ally driver for AdonisJS ally",
"description": "Azure AD ally driver for AdonisJS Ally",
"main": "build/providers/index.js",
"files": [
"build/adonis-typings",
"build/instructions.md",
"build/src",
"build/providers"
"build/providers",
"build/standalone.js",
"build/standalone.d.ts",
"build/instructions.md"
],
"types": "build/providers/index.d.ts",
"scripts": {
"clean": "del-cli build",
"pretest": "npm run lint",
Expand Down Expand Up @@ -60,6 +60,7 @@
"anyBranch": false
},
"peerDependencies": {
"@adonisjs/ally": "^4.0.0",
"@adonisjs/core": "^5.0.0"
},
"adonisjs": {
Expand Down
8 changes: 4 additions & 4 deletions providers/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { ApplicationContract } from '@ioc:Adonis/Core/Application'

export default class AADProvider {
export default class AZureADProvider {
constructor(protected app: ApplicationContract) {}

public async boot() {
const Ally = this.app.container.resolveBinding('Adonis/Addons/Ally')
const { AAD } = await import('../src/AzureAD')
const { AZureADDriver } = await import('../src/AzureAD')

Ally.extend('AzureAD', (_, __, config, ctx) => {
return new AAD(ctx, config)
Ally.extend('azuread', (_, __, config, ctx) => {
return new AZureADDriver(ctx, config)
})
}
}
85 changes: 70 additions & 15 deletions src/AzureAD/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,72 @@
|
*/

import type { AllyUserContract, ApiRequestContract } from '@ioc:Adonis/Addons/Ally'
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import { ApiRequest, Oauth2Driver, RedirectRequest } from '@adonisjs/ally/build/standalone'
import type {
AADAccessToken,
AADConfig,
AADScopes,
UserFields,
UserFieldsAndToken,
UserInfo,
} from '../types'
import { Oauth2Driver, ApiRequest, RedirectRequest } from '@adonisjs/ally/build/standalone'
AllyUserContract,
ApiRequestContract,
LiteralStringUnion,
} from '@ioc:Adonis/Addons/Ally'
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'

export type AzureADAccessToken = {
token: string
type: string
token_type: string
scope: string
expires_in: number
ext_expires_in: number
access_token: string
refresh_token: string
id_token: string
}

export type AZureADScopes = string

export type AZureADConfig = {
driver: 'azuread'
clientId: string
clientSecret: string
callbackUrl: string
authorizeUrl?: string
accessTokenUrl?: string
userInfoUrl?: string
scopes?: LiteralStringUnion<AZureADScopes>[]
}

export type UserInfo = {
'@odata.context': string
'@odata.id': string
'businessPhones': string[]
'displayName': string
'givenName': string
'jobTitle': string
'mail': string
'mobilePhone': string
'officeLocation': string
'preferredLanguage'?: any
'surname': string
'userPrincipalName': string
'id': string
}

export type UserFields = {
id: string
avatarUrl: string | null
nickName: string
displayName?: string | undefined
name: string
email: string | null
emailVerificationState: 'verified' | 'unverified' | 'unsupported'
original: UserInfo | null
}

export interface UserFieldsAndToken extends UserFields {
token: {
token: string
type: 'bearer'
}
}

/**
* Driver implementation. It is mostly configuration driven except the user calls
Expand All @@ -29,7 +84,7 @@ import { Oauth2Driver, ApiRequest, RedirectRequest } from '@adonisjs/ally/build/
* Change "AAD" to something more relevant
* ------------------------------------------------
*/
export class AAD extends Oauth2Driver<AADAccessToken, AADScopes> {
export class AZureADDriver extends Oauth2Driver<AzureADAccessToken, AZureADScopes> {
/**
* The URL for the authority data
*
Expand Down Expand Up @@ -96,7 +151,7 @@ export class AAD extends Oauth2Driver<AADAccessToken, AADScopes> {
*/
protected scopesSeparator = ' '

constructor(ctx: HttpContextContract, public config: AADConfig) {
constructor(ctx: HttpContextContract, public config: AZureADConfig) {
super(ctx, config)

config.scopes = config.scopes || ['openid', 'profile', 'email', 'offline_access']
Expand All @@ -116,7 +171,7 @@ export class AAD extends Oauth2Driver<AADAccessToken, AADScopes> {
/**
* Configuring the redirect request with defaults
*/
protected configureRedirectRequest(request: RedirectRequest<AADScopes>): void {
protected configureRedirectRequest(request: RedirectRequest<AZureADScopes>): void {
/**
* Define user defined scopes or the default one's
*/
Expand Down Expand Up @@ -200,7 +255,7 @@ export class AAD extends Oauth2Driver<AADAccessToken, AADScopes> {
*/
public async user(
callback?: (request: ApiRequest) => void
): Promise<AllyUserContract<AADAccessToken>> {
): Promise<AllyUserContract<AzureADAccessToken>> {
const accessToken = await this.accessToken()

/**
Expand All @@ -226,7 +281,7 @@ export class AAD extends Oauth2Driver<AADAccessToken, AADScopes> {

return {
...user,
token: { token, type: 'bearer' as const },
token: { token, type: 'bearer' },
}
}
}
85 changes: 0 additions & 85 deletions src/types.d.ts

This file was deleted.