@ctx-core/auth0-management 8.0.2 → 9.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/bin/add-grant-password-auth0.mjs +2 -2
- package/bin/getAll-client-grants-auth0.mjs +3 -3
- package/package.json +5 -5
- package/src/auth0_audience_.d.ts +2 -0
- package/src/auth0_audience_.js +10 -0
- package/src/auth0_management_.d.ts +4 -4
- package/src/auth0_management_.js +0 -1
- package/src/auth0_management_client_credentials_body_.d.ts +3 -0
- package/src/auth0_management_client_credentials_body_.js +13 -0
- package/src/auth0_management_token_.d.ts +3 -0
- package/src/auth0_management_token_.js +12 -0
- package/src/get_auth0_v2_client_grants.d.ts +10 -0
- package/src/get_auth0_v2_client_grants.js +26 -0
- package/src/get_auth0_v2_user.d.ts +10 -0
- package/src/get_auth0_v2_user.js +25 -0
- package/src/get_auth0_v2_users_by_email.d.ts +10 -0
- package/src/get_auth0_v2_users_by_email.js +26 -0
- package/src/index.d.ts +8 -8
- package/src/index.js +8 -8
- package/src/patch_auth0_v2_client.d.ts +11 -0
- package/src/patch_auth0_v2_client.js +26 -0
- package/src/patch_auth0_v2_user.d.ts +10 -0
- package/src/patch_auth0_v2_user.js +34 -0
- package/tsconfig.json +0 -2
- package/src/auth0_audience__b.d.ts +0 -3
- package/src/auth0_audience__b.js +0 -11
- package/src/auth0_management_client_credentials_body__b.d.ts +0 -4
- package/src/auth0_management_client_credentials_body__b.js +0 -16
- package/src/auth0_management_token__b.d.ts +0 -4
- package/src/auth0_management_token__b.js +0 -14
- package/src/get_auth0_v2_client_grants_b.d.ts +0 -10
- package/src/get_auth0_v2_client_grants_b.js +0 -26
- package/src/get_auth0_v2_user_b.d.ts +0 -9
- package/src/get_auth0_v2_user_b.js +0 -23
- package/src/get_auth0_v2_users_by_email_b.d.ts +0 -11
- package/src/get_auth0_v2_users_by_email_b.js +0 -25
- package/src/patch_auth0_v2_client_b.d.ts +0 -11
- package/src/patch_auth0_v2_client_b.js +0 -26
- package/src/patch_auth0_v2_user_b.d.ts +0 -10
- package/src/patch_auth0_v2_user_b.js +0 -31
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @ctx-core/auth0-management
|
|
2
2
|
|
|
3
|
+
## 9.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- update dependencies
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @ctx-core/fetch-undici@1.1.3
|
|
10
|
+
|
|
11
|
+
## 9.0.0
|
|
12
|
+
|
|
13
|
+
### Major Changes
|
|
14
|
+
|
|
15
|
+
- flatten functions: remove \_b suffix from exports
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
- @ctx-core/auth0@30.0.0
|
|
21
|
+
- @ctx-core/fetch-undici@1.1.1
|
|
22
|
+
|
|
23
|
+
## 8.0.4
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- update dependencies
|
|
28
|
+
|
|
29
|
+
## 8.0.3
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- update dependencies
|
|
34
|
+
|
|
3
35
|
## 8.0.2
|
|
4
36
|
|
|
5
37
|
### Patch Changes
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { ctx_ } from '@ctx-core/object'
|
|
3
|
-
import {
|
|
3
|
+
import { patch_auth0_v2_client } from '../src/index.js'
|
|
4
4
|
await main()
|
|
5
5
|
async function main() {
|
|
6
6
|
const ctx = ctx_()
|
|
7
|
-
const [client] = await
|
|
7
|
+
const [client] = await patch_auth0_v2_client(ctx, {
|
|
8
8
|
json: {
|
|
9
9
|
grant_types: [
|
|
10
10
|
'password',
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { ctx_ } from '@ctx-core/object'
|
|
3
|
-
import {
|
|
3
|
+
import { get_auth0_v2_client_grants, auth0_audience_ } from '../src/index.js'
|
|
4
4
|
await main()
|
|
5
5
|
async function main() {
|
|
6
6
|
const ctx = ctx_()
|
|
7
|
-
const [json] = await
|
|
7
|
+
const [json] = await get_auth0_v2_client_grants(ctx, {
|
|
8
8
|
json: {
|
|
9
9
|
client_id: process.env.AUTH0_CLIENT_ID,
|
|
10
|
-
audience:
|
|
10
|
+
audience: auth0_audience_(ctx)
|
|
11
11
|
}
|
|
12
12
|
})
|
|
13
13
|
console.info(JSON.stringify(json, null, 2))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ctx-core/auth0-management",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.1",
|
|
4
4
|
"description": "ctx-core auth0 management api",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ctx-core",
|
|
@@ -30,14 +30,14 @@
|
|
|
30
30
|
"getAll-client-grants-auth0": "./bin/getAll-client-grants-auth0.mjs"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@ctx-core/auth0": "^
|
|
34
|
-
"@ctx-core/fetch-undici": "^1.1.
|
|
33
|
+
"@ctx-core/auth0": "^30.0.1",
|
|
34
|
+
"@ctx-core/fetch-undici": "^1.1.3",
|
|
35
35
|
"@ctx-core/object": "^22.0.13",
|
|
36
36
|
"@ctx-core/uri": "^12.0.38",
|
|
37
|
-
"auth0": "^2.38.
|
|
37
|
+
"auth0": "^2.38.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types/auth0": "^2.34.
|
|
40
|
+
"@types/auth0": "^2.34.11",
|
|
41
41
|
"@types/auth0-js": "^9.14.5",
|
|
42
42
|
"c8": "^7.11.0",
|
|
43
43
|
"check-dts": "^0.6.6",
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AUTH0_DOMAIN$_ } from '@ctx-core/auth0'
|
|
2
|
+
import { be_ } from '@ctx-core/object'
|
|
3
|
+
/** @type {import('./auth0_audience_.d.ts').auth0_audience_} */
|
|
4
|
+
/**
|
|
5
|
+
* @param {import('@ctx-core/object').Ctx}ctx
|
|
6
|
+
* @return {string}
|
|
7
|
+
*/
|
|
8
|
+
export function auth0_audience_(ctx) {
|
|
9
|
+
return `https://${AUTH0_DOMAIN$_(ctx).$}/api/v2/`
|
|
10
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ManagementClient } from 'auth0'
|
|
2
2
|
export declare function auth0_management_(
|
|
3
3
|
params?:auth0_management_params_I
|
|
4
|
-
):ManagementClient<import('auth0').AppMetadata, import('auth0').UserMetadata
|
|
4
|
+
):ManagementClient<import('auth0').AppMetadata, import('auth0').UserMetadata>
|
|
5
5
|
export interface auth0_management_params_I {
|
|
6
|
-
domain?:string
|
|
7
|
-
clientId?:string
|
|
8
|
-
clientSecret?:string
|
|
6
|
+
domain?:string
|
|
7
|
+
clientId?:string
|
|
8
|
+
clientSecret?:string
|
|
9
9
|
}
|
package/src/auth0_management_.js
CHANGED
|
@@ -2,7 +2,6 @@ import { ManagementClient } from 'auth0'
|
|
|
2
2
|
/**
|
|
3
3
|
* @param {import('./auth0_management_.d.ts').auth0_management_params_I} params
|
|
4
4
|
* @returns {import('auth0').ManagementClient}
|
|
5
|
-
* @private
|
|
6
5
|
*/
|
|
7
6
|
export function auth0_management_(params = {}) {
|
|
8
7
|
const domain = params.domain || process.env.AUTH0_DOMAIN || ''
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { auth0_audience_ } from './auth0_audience_.js'
|
|
2
|
+
/**
|
|
3
|
+
* @param {import('@ctx-core/object').Ctx}ctx
|
|
4
|
+
* @return {import('@ctx-core/auth0').post_auth0_oauth_token_body_I}
|
|
5
|
+
*/
|
|
6
|
+
export function auth0_management_client_credentials_body_(ctx) {
|
|
7
|
+
return {
|
|
8
|
+
grant_type: 'client_credentials',
|
|
9
|
+
client_id: process.env.AUTH0_MANAGEMENT_ID,
|
|
10
|
+
client_secret: process.env.AUTH0_MANAGEMENT_SECRET,
|
|
11
|
+
audience: auth0_audience_(ctx)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { post_auth0_oauth_token } from '@ctx-core/auth0'
|
|
2
|
+
import { auth0_management_client_credentials_body_ } from './auth0_management_client_credentials_body_.js'
|
|
3
|
+
/**
|
|
4
|
+
* @param {import('@ctx-core/object').Ctx}ctx
|
|
5
|
+
* @return {Promise<import('@ctx-core/auth0').auth0_token_T>}
|
|
6
|
+
*/
|
|
7
|
+
export async function auth0_management_token_(ctx) {
|
|
8
|
+
const [token_response] = await post_auth0_oauth_token(
|
|
9
|
+
ctx, auth0_management_client_credentials_body_(ctx)
|
|
10
|
+
)
|
|
11
|
+
return token_response
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import { Ctx } from '@ctx-core/object'
|
|
3
|
+
import type { CreateClientGrant } from 'auth0'
|
|
4
|
+
export declare function get_auth0_v2_client_grants(
|
|
5
|
+
ctx:Ctx, params:get_auth0_v2_client_grants_params_T
|
|
6
|
+
):Promise<[CreateClientGrant, Response]>
|
|
7
|
+
export interface get_auth0_v2_client_grants_params_T {
|
|
8
|
+
query?:string
|
|
9
|
+
json?:any
|
|
10
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { verify_access_token_header_authorization, AUTH0_DOMAIN$_ } from '@ctx-core/auth0'
|
|
2
|
+
import { fetch } from '@ctx-core/fetch-undici'
|
|
3
|
+
import { query_str_ } from '@ctx-core/uri'
|
|
4
|
+
import { auth0_management_token_ } from './auth0_management_token_.js'
|
|
5
|
+
/** @typedef {import('auth0').CreateClientGrant}CreateClientGrant */
|
|
6
|
+
/**
|
|
7
|
+
* @param {import('@ctx-core/object').Ctx}ctx
|
|
8
|
+
* @param {import('./get_auth0_v2_client_grants.d.ts').get_auth0_v2_client_grants_params_T}params
|
|
9
|
+
* @return {Promise<[CreateClientGrant, Response]>}
|
|
10
|
+
*/
|
|
11
|
+
export async function get_auth0_v2_client_grants(ctx, params) {
|
|
12
|
+
const { query, json } = params
|
|
13
|
+
const auth0_token = await auth0_management_token_(ctx)
|
|
14
|
+
const authorization = verify_access_token_header_authorization(auth0_token)
|
|
15
|
+
const url = `https://${AUTH0_DOMAIN$_(ctx).$}/api/v2/client-grants?${query || query_str_(json)}`
|
|
16
|
+
const res = await fetch(url, {
|
|
17
|
+
method: 'GET',
|
|
18
|
+
headers: {
|
|
19
|
+
'Content-Type': 'application/json',
|
|
20
|
+
authorization
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
/** @type {CreateClientGrant} */
|
|
24
|
+
const create_client_grant = await res.json()
|
|
25
|
+
return [create_client_grant, res]
|
|
26
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import { Ctx } from '@ctx-core/object'
|
|
3
|
+
import { User } from 'auth0'
|
|
4
|
+
export declare function get_auth0_v2_user(
|
|
5
|
+
ctx:Ctx, params:get_auth0_v2_user_params_T
|
|
6
|
+
):Promise<[User, Response]>
|
|
7
|
+
export interface get_auth0_v2_user_params_T {
|
|
8
|
+
AUTH0_DOMAIN:string
|
|
9
|
+
user_id:string
|
|
10
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { verify_access_token_header_authorization } from '@ctx-core/auth0'
|
|
2
|
+
import { fetch } from '@ctx-core/fetch-undici'
|
|
3
|
+
import { auth0_management_token_ } from './auth0_management_token_.js'
|
|
4
|
+
/** @typedef {import('auth0').User}User */
|
|
5
|
+
/**
|
|
6
|
+
* @param {import('@ctx-core/object').Ctx}ctx
|
|
7
|
+
* @param {import('./get_auth0_v2_user.d.ts').get_auth0_v2_user_params_T}params
|
|
8
|
+
* @return {Promise<[User, Response]>}
|
|
9
|
+
*/
|
|
10
|
+
export async function get_auth0_v2_user(ctx, params) {
|
|
11
|
+
const { AUTH0_DOMAIN, user_id } = params
|
|
12
|
+
const auth0_token = await auth0_management_token_(ctx)
|
|
13
|
+
const authorization = verify_access_token_header_authorization(auth0_token)
|
|
14
|
+
const url = `https://${AUTH0_DOMAIN}/api/v2/users/${user_id}`
|
|
15
|
+
const res = await fetch(url, {
|
|
16
|
+
method: 'GET',
|
|
17
|
+
headers: {
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
authorization
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
/** @type {User} */
|
|
23
|
+
const user = await res.json()
|
|
24
|
+
return [user, res]
|
|
25
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import type { Auth0UserProfile } from 'auth0-js'
|
|
3
|
+
import { Ctx } from '@ctx-core/object'
|
|
4
|
+
export declare function get_auth0_v2_users_by_email(
|
|
5
|
+
ctx:Ctx, params:get_auth0_v2_users_by_email_params_T
|
|
6
|
+
):Promise<[Auth0UserProfile[], Response]>
|
|
7
|
+
export declare type get_auth0_v2_users_by_email_params_T = {
|
|
8
|
+
email:string
|
|
9
|
+
AUTH0_DOMAIN?:string
|
|
10
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { verify_access_token_header_authorization, AUTH0_DOMAIN$_ } from '@ctx-core/auth0'
|
|
2
|
+
import { fetch } from '@ctx-core/fetch-undici'
|
|
3
|
+
import { auth0_management_token_ } from './auth0_management_token_.js'
|
|
4
|
+
/** @type {import('auth0-js').Auth0UserProfile}Auth0UserProfile */
|
|
5
|
+
/**
|
|
6
|
+
* @param {import('@ctx-core/object').Ctx}ctx
|
|
7
|
+
* @param {import('./get_auth0_v2_users_by_email.d.ts').get_auth0_v2_users_by_email_params_T}params
|
|
8
|
+
* @return {Promise<[Auth0UserProfile[], Response]>}
|
|
9
|
+
*/
|
|
10
|
+
export async function get_auth0_v2_users_by_email(ctx, params) {
|
|
11
|
+
const { email } = params
|
|
12
|
+
const AUTH0_DOMAIN = params.AUTH0_DOMAIN || AUTH0_DOMAIN$_(ctx).$
|
|
13
|
+
const auth0_token = await auth0_management_token_(ctx)
|
|
14
|
+
const authorization = verify_access_token_header_authorization(auth0_token)
|
|
15
|
+
const url = `https://${AUTH0_DOMAIN}/api/v2/users-by-email?email=${encodeURIComponent(email)}`
|
|
16
|
+
const res = await fetch(url, {
|
|
17
|
+
method: 'GET',
|
|
18
|
+
headers: {
|
|
19
|
+
'Content-Type': 'application/json',
|
|
20
|
+
authorization
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
/** @type {Auth0UserProfile[]} */
|
|
24
|
+
const auth0_user_profile_a = await res.json()
|
|
25
|
+
return [auth0_user_profile_a, res]
|
|
26
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './auth0_audience_'
|
|
2
2
|
export * from './auth0_management_'
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './
|
|
3
|
+
export * from './auth0_management_client_credentials_body_'
|
|
4
|
+
export * from './auth0_management_token_'
|
|
5
|
+
export * from './get_auth0_v2_client_grants'
|
|
6
|
+
export * from './get_auth0_v2_user'
|
|
7
|
+
export * from './get_auth0_v2_users_by_email'
|
|
8
|
+
export * from './patch_auth0_v2_client'
|
|
9
|
+
export * from './patch_auth0_v2_user'
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './auth0_audience_.js'
|
|
2
2
|
export * from './auth0_management_.js'
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './
|
|
3
|
+
export * from './auth0_management_client_credentials_body_.js'
|
|
4
|
+
export * from './auth0_management_token_.js'
|
|
5
|
+
export * from './get_auth0_v2_client_grants.js'
|
|
6
|
+
export * from './get_auth0_v2_user.js'
|
|
7
|
+
export * from './get_auth0_v2_users_by_email.js'
|
|
8
|
+
export * from './patch_auth0_v2_client.js'
|
|
9
|
+
export * from './patch_auth0_v2_user.js'
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import { Ctx } from '@ctx-core/object'
|
|
3
|
+
import type { Client } from 'auth0'
|
|
4
|
+
export declare function patch_auth0_v2_client(
|
|
5
|
+
ctx:Ctx, params:patch_auth0_v2_client_params_T
|
|
6
|
+
):Promise<[Client, Response]>
|
|
7
|
+
export interface patch_auth0_v2_client_params_T {
|
|
8
|
+
client_id?:string
|
|
9
|
+
body?:string
|
|
10
|
+
json?:unknown
|
|
11
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { verify_access_token_header_authorization, AUTH0_DOMAIN$_ } from '@ctx-core/auth0'
|
|
2
|
+
import { fetch } from '@ctx-core/fetch-undici'
|
|
3
|
+
import { auth0_management_token_ } from './auth0_management_token_.js'
|
|
4
|
+
/** @typedef {import('auth0').Client}Client */
|
|
5
|
+
/**
|
|
6
|
+
* @param {import('@ctx-core/object').Ctx}ctx
|
|
7
|
+
* @param {import('./patch_auth0_v2_client.d.ts').patch_auth0_v2_client_params_T}params
|
|
8
|
+
* @return {Promise<[Client, Response]>}
|
|
9
|
+
*/
|
|
10
|
+
export async function patch_auth0_v2_client(ctx, params) {
|
|
11
|
+
const { client_id = process.env.AUTH0_CLIENT_ID, body, json, } = params
|
|
12
|
+
const auth0_token = await auth0_management_token_(ctx)
|
|
13
|
+
const authorization = verify_access_token_header_authorization(auth0_token)
|
|
14
|
+
const url = `https://${AUTH0_DOMAIN$_(ctx).$}/api/v2/clients/${client_id}`
|
|
15
|
+
const res = await fetch(url, {
|
|
16
|
+
method: 'PATCH',
|
|
17
|
+
headers: {
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
authorization
|
|
20
|
+
},
|
|
21
|
+
body: body || JSON.stringify(json)
|
|
22
|
+
})
|
|
23
|
+
/** @type {Client} */
|
|
24
|
+
const client = await res.json()
|
|
25
|
+
return [client, res]
|
|
26
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import { B, Ctx } from '@ctx-core/object'
|
|
3
|
+
import type { UserData, UpdateUserData } from 'auth0'
|
|
4
|
+
import type { Auth0Error } from 'auth0-js'
|
|
5
|
+
export declare function patch_auth0_v2_user(
|
|
6
|
+
ctx:Ctx, user_id:string, data:patch_auth0_v2_user_data_T
|
|
7
|
+
):Promise<[UpdateUserData|Auth0Error, Response]>
|
|
8
|
+
export interface patch_auth0_v2_user_data_T extends Partial<UserData> {
|
|
9
|
+
password?:string
|
|
10
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { verify_access_token_header_authorization, AUTH0_DOMAIN$_ } from '@ctx-core/auth0'
|
|
2
|
+
import { fetch } from '@ctx-core/fetch-undici'
|
|
3
|
+
import { auth0_management_token_ } from './auth0_management_token_.js'
|
|
4
|
+
/** @typedef {import('auth0').UpdateUserData}UpdateUserData */
|
|
5
|
+
/** @typedef {import('auth0').Auth0Error}Auth0Error */
|
|
6
|
+
/**
|
|
7
|
+
* @param {import('@ctx-core/object').Ctx}ctx
|
|
8
|
+
* @param {string}user_id
|
|
9
|
+
* @param {import('./patch_auth0_v2_user.d.ts').patch_auth0_v2_user_data_T}data
|
|
10
|
+
* @return {Promise<[UpdateUserData|Auth0Error, Response]>}
|
|
11
|
+
* @see {@link https://auth0.com/docs/api-auth/tutorials/client-credentials}
|
|
12
|
+
* @see {@link https://auth0.com/docs/api-auth/which-oauth-flow-to-use}
|
|
13
|
+
* @see {@link https://auth0.com/docs/clients/client-grant-types}
|
|
14
|
+
* @see {@link https://auth0.com/docs/api-auth/grant/authorization-code}
|
|
15
|
+
* @see {@link https://auth0.com/docs/protocols/oauth2}
|
|
16
|
+
*/
|
|
17
|
+
export async function patch_auth0_v2_user(
|
|
18
|
+
ctx, user_id, data
|
|
19
|
+
) {
|
|
20
|
+
const auth0_management_token = await auth0_management_token_(ctx)
|
|
21
|
+
const authorization = verify_access_token_header_authorization(auth0_management_token)
|
|
22
|
+
const url = `https://${AUTH0_DOMAIN$_(ctx).$}/api/v2/users/${user_id}`
|
|
23
|
+
const res = await fetch(url, {
|
|
24
|
+
method: 'PATCH',
|
|
25
|
+
headers: {
|
|
26
|
+
'Content-Type': 'application/json',
|
|
27
|
+
authorization
|
|
28
|
+
},
|
|
29
|
+
body: JSON.stringify(data)
|
|
30
|
+
})
|
|
31
|
+
/** @type {UpdateUserData|Auth0Error} */
|
|
32
|
+
const update_user_data_or_auth0_error = await res.json()
|
|
33
|
+
return [update_user_data_or_auth0_error, res]
|
|
34
|
+
}
|
package/tsconfig.json
CHANGED
package/src/auth0_audience__b.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { AUTH0_DOMAIN$_b } from '@ctx-core/auth0'
|
|
2
|
-
import { be_ } from '@ctx-core/object'
|
|
3
|
-
const key = 'auth0_audience_'
|
|
4
|
-
/** @type {import('./auth0_audience__b.d.ts').auth0_audience__b} */
|
|
5
|
-
export const auth0_audience__b = be_(key, ctx=>{
|
|
6
|
-
const AUTH0_DOMAIN$ = AUTH0_DOMAIN$_b(ctx)
|
|
7
|
-
return auth0_audience_fn
|
|
8
|
-
function auth0_audience_fn() {
|
|
9
|
-
return `https://${AUTH0_DOMAIN$.$}/api/v2/`
|
|
10
|
-
}
|
|
11
|
-
})
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { post_auth0_oauth_token_body_I } from '@ctx-core/auth0'
|
|
2
|
-
import { B } from '@ctx-core/object'
|
|
3
|
-
export declare const auth0_management_client_credentials_body__b:B<auth0_management_client_credentials_body__T>
|
|
4
|
-
export declare type auth0_management_client_credentials_body__T = ()=>post_auth0_oauth_token_body_I;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { be_ } from '@ctx-core/object'
|
|
2
|
-
import { auth0_audience__b } from './auth0_audience__b.js'
|
|
3
|
-
const key = 'auth0_management_client_credentials_body_'
|
|
4
|
-
/** @type {import('./auth0_management_client_credentials_body__b.d.ts').auth0_management_client_credentials_body__b} */
|
|
5
|
-
export const auth0_management_client_credentials_body__b = be_(key, ctx=>{
|
|
6
|
-
const auth0_audience_ = auth0_audience__b(ctx)
|
|
7
|
-
return auth0_management_client_credentials_body_
|
|
8
|
-
function auth0_management_client_credentials_body_() {
|
|
9
|
-
return {
|
|
10
|
-
grant_type: 'client_credentials',
|
|
11
|
-
client_id: process.env.AUTH0_MANAGEMENT_ID,
|
|
12
|
-
client_secret: process.env.AUTH0_MANAGEMENT_SECRET,
|
|
13
|
-
audience: auth0_audience_()
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
})
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { post_auth0_oauth_token_b } from '@ctx-core/auth0'
|
|
2
|
-
import { be_ } from '@ctx-core/object'
|
|
3
|
-
import { auth0_management_client_credentials_body__b } from './auth0_management_client_credentials_body__b.js'
|
|
4
|
-
const key = 'auth0_management_token_'
|
|
5
|
-
/** @type {import('./auth0_management_token__b.d.ts').auth0_management_token__b} */
|
|
6
|
-
export const auth0_management_token__b = be_(key, ctx=>{
|
|
7
|
-
const auth0_management_client_credentials_body_fn = auth0_management_client_credentials_body__b(ctx)
|
|
8
|
-
return auth0_management_token_
|
|
9
|
-
async function auth0_management_token_() {
|
|
10
|
-
const management_client_credentials = auth0_management_client_credentials_body_fn()
|
|
11
|
-
const [token_response] = await post_auth0_oauth_token_b(ctx)(management_client_credentials)
|
|
12
|
-
return token_response
|
|
13
|
-
}
|
|
14
|
-
})
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/// <reference lib="dom" />
|
|
2
|
-
import { B } from '@ctx-core/object'
|
|
3
|
-
import type { CreateClientGrant } from 'auth0'
|
|
4
|
-
export declare const get_auth0_v2_client_grants_b:B<get_auth0_v2_client_grants_T>
|
|
5
|
-
export interface get_auth0_v2_client_grants_params_I {
|
|
6
|
-
query?:string;
|
|
7
|
-
json?:any;
|
|
8
|
-
}
|
|
9
|
-
export declare type get_auth0_v2_client_grants_T =
|
|
10
|
-
(params:get_auth0_v2_client_grants_params_I)=>Promise<[CreateClientGrant, Response]>;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { verify_access_token_header_authorization_, AUTH0_DOMAIN$_b } from '@ctx-core/auth0'
|
|
2
|
-
import { fetch } from '@ctx-core/fetch-undici'
|
|
3
|
-
import { be_ } from '@ctx-core/object'
|
|
4
|
-
import { query_str_ } from '@ctx-core/uri'
|
|
5
|
-
import { auth0_management_token__b } from './auth0_management_token__b.js'
|
|
6
|
-
const key = 'get_auth0_v2_client_grants'
|
|
7
|
-
/** @type {import('./get_auth0_v2_client_grants_b.d.ts').get_auth0_v2_client_grants_b} */
|
|
8
|
-
export const get_auth0_v2_client_grants_b = be_(key, ctx=>{
|
|
9
|
-
const auth0_management_token_ = auth0_management_token__b(ctx)
|
|
10
|
-
const AUTH0_DOMAIN$ = AUTH0_DOMAIN$_b(ctx)
|
|
11
|
-
return get_auth0_v2_client_grants
|
|
12
|
-
async function get_auth0_v2_client_grants(params) {
|
|
13
|
-
const { query, json } = params
|
|
14
|
-
const auth0_token = await auth0_management_token_()
|
|
15
|
-
const authorization = verify_access_token_header_authorization_(auth0_token)
|
|
16
|
-
const url = `https://${AUTH0_DOMAIN$.$}/api/v2/client-grants?${query || query_str_(json)}`
|
|
17
|
-
const res = await fetch(url, {
|
|
18
|
-
method: 'GET',
|
|
19
|
-
headers: {
|
|
20
|
-
'Content-Type': 'application/json',
|
|
21
|
-
authorization
|
|
22
|
-
}
|
|
23
|
-
})
|
|
24
|
-
return [await res.json(), res]
|
|
25
|
-
}
|
|
26
|
-
})
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { B } from '@ctx-core/object'
|
|
2
|
-
import { User } from 'auth0'
|
|
3
|
-
export declare const get_auth0_v2_user_b:B<get_auth0_v2_user_T>
|
|
4
|
-
export interface get_auth0_v2_user_params_T {
|
|
5
|
-
AUTH0_DOMAIN:string;
|
|
6
|
-
user_id:string;
|
|
7
|
-
}
|
|
8
|
-
export declare type get_auth0_v2_user_T =
|
|
9
|
-
(params:get_auth0_v2_user_params_T)=>Promise<[User, Response]>;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { verify_access_token_header_authorization_ } from '@ctx-core/auth0'
|
|
2
|
-
import { fetch } from '@ctx-core/fetch-undici'
|
|
3
|
-
import { be_ } from '@ctx-core/object'
|
|
4
|
-
import { auth0_management_token__b } from './auth0_management_token__b.js'
|
|
5
|
-
const key = 'get_auth0_v2_user'
|
|
6
|
-
/** @type {import('./get_auth0_v2_user_b.d.ts').get_auth0_v2_user_b} */
|
|
7
|
-
export const get_auth0_v2_user_b = be_(key, ctx=>{
|
|
8
|
-
const auth0_management_token_ = auth0_management_token__b(ctx)
|
|
9
|
-
return get_auth0_v2_user
|
|
10
|
-
async function get_auth0_v2_user({ AUTH0_DOMAIN, user_id }) {
|
|
11
|
-
const auth0_token = await auth0_management_token_()
|
|
12
|
-
const authorization = verify_access_token_header_authorization_(auth0_token)
|
|
13
|
-
const url = `https://${AUTH0_DOMAIN}/api/v2/users/${user_id}`
|
|
14
|
-
const res = await fetch(url, {
|
|
15
|
-
method: 'GET',
|
|
16
|
-
headers: {
|
|
17
|
-
'Content-Type': 'application/json',
|
|
18
|
-
authorization
|
|
19
|
-
}
|
|
20
|
-
})
|
|
21
|
-
return [await res.json(), res]
|
|
22
|
-
}
|
|
23
|
-
})
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Auth0UserProfile } from 'auth0-js'
|
|
2
|
-
import { B } from '@ctx-core/object'
|
|
3
|
-
export declare const get_auth0_v2_users_by_email_b:B<get_auth0_v2_users_by_email_T>
|
|
4
|
-
export declare type get_auth0_v2_users_by_email_params_I = {
|
|
5
|
-
email:string;
|
|
6
|
-
AUTH0_DOMAIN?:string;
|
|
7
|
-
};
|
|
8
|
-
export declare type get_auth0_v2_users_by_email_T = (
|
|
9
|
-
params:get_auth0_v2_users_by_email_params_I
|
|
10
|
-
)=>Promise<[get_auth0_v2_users_by_email_response_T, Response]>;
|
|
11
|
-
export declare type get_auth0_v2_users_by_email_response_T = Auth0UserProfile[];
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { verify_access_token_header_authorization_, AUTH0_DOMAIN$_b } from '@ctx-core/auth0'
|
|
2
|
-
import { fetch } from '@ctx-core/fetch-undici'
|
|
3
|
-
import { be_ } from '@ctx-core/object'
|
|
4
|
-
import { auth0_management_token__b } from './auth0_management_token__b.js'
|
|
5
|
-
const key = 'get_auth0_v2_users_by_email'
|
|
6
|
-
/** @type {import('./get_auth0_v2_users_by_email_b.d.ts').get_auth0_v2_users_by_email_b} */
|
|
7
|
-
export const get_auth0_v2_users_by_email_b = be_(key, ctx=>{
|
|
8
|
-
const auth0_management_token_ = auth0_management_token__b(ctx)
|
|
9
|
-
return get_auth0_v2_users_by_email
|
|
10
|
-
async function get_auth0_v2_users_by_email(params) {
|
|
11
|
-
const { email } = params
|
|
12
|
-
const AUTH0_DOMAIN = params.AUTH0_DOMAIN || AUTH0_DOMAIN$_b(ctx).$
|
|
13
|
-
const auth0_token = await auth0_management_token_()
|
|
14
|
-
const authorization = verify_access_token_header_authorization_(auth0_token)
|
|
15
|
-
const url = `https://${AUTH0_DOMAIN}/api/v2/users-by-email?email=${encodeURIComponent(email)}`
|
|
16
|
-
const res = await fetch(url, {
|
|
17
|
-
method: 'GET',
|
|
18
|
-
headers: {
|
|
19
|
-
'Content-Type': 'application/json',
|
|
20
|
-
authorization
|
|
21
|
-
}
|
|
22
|
-
})
|
|
23
|
-
return [await res.json(), res]
|
|
24
|
-
}
|
|
25
|
-
})
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/// <reference lib="dom" />
|
|
2
|
-
import { B } from '@ctx-core/object'
|
|
3
|
-
import type { Client } from 'auth0'
|
|
4
|
-
export declare const patch_auth0_v2_client_b:B<patch_auth0_v2_client_T>
|
|
5
|
-
export interface patch_auth0_v2_client_params_T {
|
|
6
|
-
client_id?:string;
|
|
7
|
-
body?:string;
|
|
8
|
-
json?:unknown;
|
|
9
|
-
}
|
|
10
|
-
export declare type patch_auth0_v2_client_T =
|
|
11
|
-
(params:patch_auth0_v2_client_params_T)=>Promise<[Client, Response]>;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { verify_access_token_header_authorization_, AUTH0_DOMAIN$_b } from '@ctx-core/auth0'
|
|
2
|
-
import { fetch } from '@ctx-core/fetch-undici'
|
|
3
|
-
import { be_ } from '@ctx-core/object'
|
|
4
|
-
import { auth0_management_token__b } from './auth0_management_token__b.js'
|
|
5
|
-
const key = 'patch_auth0_v2_client'
|
|
6
|
-
/** @type {import('./patch_auth0_v2_client_b.d.ts').patch_auth0_v2_client_b} */
|
|
7
|
-
export const patch_auth0_v2_client_b = be_(key, ctx=>{
|
|
8
|
-
const auth0_management_token_ = auth0_management_token__b(ctx)
|
|
9
|
-
const AUTH0_DOMAIN$ = AUTH0_DOMAIN$_b(ctx)
|
|
10
|
-
return patch_auth0_v2_client
|
|
11
|
-
async function patch_auth0_v2_client(params) {
|
|
12
|
-
const { client_id = process.env.AUTH0_CLIENT_ID, body, json, } = params
|
|
13
|
-
const auth0_token = await auth0_management_token_()
|
|
14
|
-
const authorization = verify_access_token_header_authorization_(auth0_token)
|
|
15
|
-
const url = `https://${AUTH0_DOMAIN$.$}/api/v2/clients/${client_id}`
|
|
16
|
-
const res = await fetch(url, {
|
|
17
|
-
method: 'PATCH',
|
|
18
|
-
headers: {
|
|
19
|
-
'Content-Type': 'application/json',
|
|
20
|
-
authorization
|
|
21
|
-
},
|
|
22
|
-
body: body || JSON.stringify(json)
|
|
23
|
-
})
|
|
24
|
-
return [await res.json(), res]
|
|
25
|
-
}
|
|
26
|
-
})
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/// <reference lib="dom" />
|
|
2
|
-
import { B } from '@ctx-core/object'
|
|
3
|
-
import type { UserData, UpdateUserData } from 'auth0'
|
|
4
|
-
import type { Auth0Error } from 'auth0-js'
|
|
5
|
-
export declare const patch_auth0_v2_user_b:B<patch_auth0_v2_user_T>
|
|
6
|
-
export interface patch_auth0_v2_user_data_I extends Partial<UserData> {
|
|
7
|
-
password?:string;
|
|
8
|
-
}
|
|
9
|
-
export declare type patch_auth0_v2_user_T =
|
|
10
|
-
(user_id:string, data:patch_auth0_v2_user_data_I)=>Promise<[UpdateUserData|Auth0Error, Response]>;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { verify_access_token_header_authorization_, AUTH0_DOMAIN$_b } from '@ctx-core/auth0'
|
|
2
|
-
import { fetch } from '@ctx-core/fetch-undici'
|
|
3
|
-
import { be_ } from '@ctx-core/object'
|
|
4
|
-
import { auth0_management_token__b } from './auth0_management_token__b.js'
|
|
5
|
-
const key = 'patch_auth0_v2_user'
|
|
6
|
-
/** @type {import('./patch_auth0_v2_user_b.d.ts').patch_auth0_v2_user_b} */
|
|
7
|
-
export const patch_auth0_v2_user_b = be_(key, ctx=>{
|
|
8
|
-
const auth0_management_token_ = auth0_management_token__b(ctx)
|
|
9
|
-
const AUTH0_DOMAIN$ = AUTH0_DOMAIN$_b(ctx)
|
|
10
|
-
return patch_auth0_v2_user
|
|
11
|
-
/**
|
|
12
|
-
* @see {@link https://auth0.com/docs/api-auth/tutorials/client-credentials}
|
|
13
|
-
* @see {@link https://auth0.com/docs/api-auth/which-oauth-flow-to-use}
|
|
14
|
-
* @see {@link https://auth0.com/docs/clients/client-grant-types}
|
|
15
|
-
* @see {@link https://auth0.com/docs/api-auth/grant/authorization-code}
|
|
16
|
-
* @see {@link https://auth0.com/docs/protocols/oauth2}
|
|
17
|
-
*/ async function patch_auth0_v2_user(user_id, data) {
|
|
18
|
-
const auth0_management_token = await auth0_management_token_()
|
|
19
|
-
const authorization = verify_access_token_header_authorization_(auth0_management_token)
|
|
20
|
-
const url = `https://${AUTH0_DOMAIN$.$}/api/v2/users/${user_id}`
|
|
21
|
-
const res = await fetch(url, {
|
|
22
|
-
method: 'PATCH',
|
|
23
|
-
headers: {
|
|
24
|
-
'Content-Type': 'application/json',
|
|
25
|
-
authorization
|
|
26
|
-
},
|
|
27
|
-
body: JSON.stringify(data)
|
|
28
|
-
})
|
|
29
|
-
return [await res.json(), res]
|
|
30
|
-
}
|
|
31
|
-
})
|