@ctx-core/auth0-management 9.7.0 → 9.7.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
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ctx-core/auth0-management",
|
|
3
|
-
"version": "9.7.
|
|
3
|
+
"version": "9.7.1",
|
|
4
4
|
"description": "ctx-core auth0 management api",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ctx-core",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"getAll-client-grants-auth0": "./bin/getAll-client-grants-auth0.mjs"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@ctx-core/auth0": "^
|
|
31
|
+
"@ctx-core/auth0": "^39.0.0",
|
|
32
32
|
"@ctx-core/env": "^17.2.108",
|
|
33
33
|
"@ctx-core/error": "^12.3.36",
|
|
34
34
|
"@ctx-core/fetch": "^12.11.1",
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { AUTH0_DOMAIN__set } from '@ctx-core/auth0'
|
|
2
|
+
import { ctx_ } from '@ctx-core/object'
|
|
3
|
+
import { type User } from 'auth0'
|
|
4
|
+
import { restore, stub } from 'sinon'
|
|
5
|
+
import { test } from 'uvu'
|
|
6
|
+
import { equal } from 'uvu/assert'
|
|
7
|
+
import { auth0_management__init } from '../auth0_management__init/index.js'
|
|
8
|
+
import { auth0__v2_user__GET__fetch, auth0__v2_user__GET__fetch2 } from './index.js'
|
|
9
|
+
test.after.each(()=>restore())
|
|
10
|
+
test('auth0__v2_user__GET__fetch', async ()=>{
|
|
11
|
+
const ctx = ctx_()
|
|
12
|
+
AUTH0_DOMAIN__set(ctx, 'myapp.auth0.com')
|
|
13
|
+
auth0_management__init(ctx, {
|
|
14
|
+
AUTH0_MANAGEMENT_ID: 'AUTH0_MANAGEMENT_ID',
|
|
15
|
+
AUTH0_MANAGEMENT_SECRET: 'AUTH0_MANAGEMENT_SECRET'
|
|
16
|
+
})
|
|
17
|
+
const auth0__user = auth0__user__new()
|
|
18
|
+
api_v2_user__stub(auth0__user)
|
|
19
|
+
const response = await auth0__v2_user__GET__fetch(ctx, {
|
|
20
|
+
user_id: '123'
|
|
21
|
+
})
|
|
22
|
+
equal(response.status, 200)
|
|
23
|
+
equal(await response.json(), auth0__user)
|
|
24
|
+
})
|
|
25
|
+
test('auth0__v2_user__GET__fetch2', async ()=>{
|
|
26
|
+
const ctx = ctx_()
|
|
27
|
+
AUTH0_DOMAIN__set(ctx, 'myapp.auth0.com')
|
|
28
|
+
auth0_management__init(ctx, {
|
|
29
|
+
AUTH0_MANAGEMENT_ID: 'AUTH0_MANAGEMENT_ID',
|
|
30
|
+
AUTH0_MANAGEMENT_SECRET: 'AUTH0_MANAGEMENT_SECRET'
|
|
31
|
+
})
|
|
32
|
+
const test__auth0__user = auth0__user__new()
|
|
33
|
+
api_v2_user__stub(test__auth0__user)
|
|
34
|
+
const [auth0__user, response] =
|
|
35
|
+
await auth0__v2_user__GET__fetch2(ctx, {
|
|
36
|
+
user_id: '123'
|
|
37
|
+
})
|
|
38
|
+
equal(response.status, 200)
|
|
39
|
+
equal(auth0__user, test__auth0__user)
|
|
40
|
+
})
|
|
41
|
+
test.run()
|
|
42
|
+
function auth0__user__new() {
|
|
43
|
+
return {
|
|
44
|
+
'user_id': 'auth0|507f1f77bcf86cd799439020',
|
|
45
|
+
'email': 'john.doe@gmail.com',
|
|
46
|
+
'email_verified': false,
|
|
47
|
+
'username': 'johndoe',
|
|
48
|
+
'phone_number': '+199999999999999',
|
|
49
|
+
'phone_verified': false,
|
|
50
|
+
'created_at': '',
|
|
51
|
+
'updated_at': '',
|
|
52
|
+
'identities': [
|
|
53
|
+
{
|
|
54
|
+
'connection': 'Initial-Connection',
|
|
55
|
+
'user_id': '507f1f77bcf86cd799439020',
|
|
56
|
+
'provider': 'auth0',
|
|
57
|
+
'isSocial': false
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
'app_metadata': {},
|
|
61
|
+
'user_metadata': {},
|
|
62
|
+
'picture': '',
|
|
63
|
+
'name': '',
|
|
64
|
+
'nickname': '',
|
|
65
|
+
'multifactor': [
|
|
66
|
+
''
|
|
67
|
+
],
|
|
68
|
+
'last_ip': '',
|
|
69
|
+
'last_login': '',
|
|
70
|
+
'logins_count': 0,
|
|
71
|
+
'blocked': false,
|
|
72
|
+
'given_name': '',
|
|
73
|
+
'family_name': ''
|
|
74
|
+
} as User
|
|
75
|
+
}
|
|
76
|
+
function api_v2_user__stub(auth0__user:User) {
|
|
77
|
+
const fetch = stub(globalThis, 'fetch')
|
|
78
|
+
fetch
|
|
79
|
+
.withArgs('https://myapp.auth0.com/oauth/token', {
|
|
80
|
+
method: 'POST',
|
|
81
|
+
headers: { 'Content-Type': 'application/json' },
|
|
82
|
+
body: JSON.stringify({
|
|
83
|
+
grant_type: 'client_credentials',
|
|
84
|
+
client_id: 'AUTH0_MANAGEMENT_ID',
|
|
85
|
+
client_secret: 'AUTH0_MANAGEMENT_SECRET',
|
|
86
|
+
audience: 'https://myapp.auth0.com/api/v2/',
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
.resolves(new Response(JSON.stringify({
|
|
90
|
+
access_token: 'access_token',
|
|
91
|
+
token_type: 'Bearer',
|
|
92
|
+
}), {
|
|
93
|
+
status: 200,
|
|
94
|
+
headers: {
|
|
95
|
+
'Content-Type': 'application/json'
|
|
96
|
+
}
|
|
97
|
+
}))
|
|
98
|
+
fetch.withArgs('https://myapp.auth0.com/api/v2/users/123')
|
|
99
|
+
.resolves(new Response(JSON.stringify(auth0__user), {
|
|
100
|
+
status: 200,
|
|
101
|
+
headers: {
|
|
102
|
+
'Content-Type': 'application/json'
|
|
103
|
+
}
|
|
104
|
+
}))
|
|
105
|
+
}
|
|
@@ -16,7 +16,8 @@ export async function auth0_management__token__new(ctx) {
|
|
|
16
16
|
response
|
|
17
17
|
] =
|
|
18
18
|
await auth0__oauth_token__POST__fetch2(
|
|
19
|
-
ctx,
|
|
19
|
+
ctx,
|
|
20
|
+
auth0_management__client_credentials__body__new(ctx))
|
|
20
21
|
if (!response.ok) {
|
|
21
22
|
/** @type {Auth0Error} */
|
|
22
23
|
const auth0_error = payload
|
package/COMMIT_EDITMSG
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|