@ctx-core/auth0-management 9.6.0 → 9.6.4
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/package.json +4 -5
- package/src/auth0__v2_client__GET__fetch/index.js +1 -1
- package/src/auth0__v2_client_grants__GET__fetch/index.js +1 -1
- package/src/auth0__v2_user__GET__fetch/index.js +1 -1
- package/src/auth0__v2_user__PATCH__fetch/index.js +1 -1
- package/src/auth0__v2_users_by_email__GET__fetch/index.js +2 -5
- package/src/auth0__v2_users_by_email__GET__fetch/index.test.ts +109 -0
- package/src/auth0_management__token__new/index.test.ts +29 -26
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @ctx-core/auth0-management
|
|
2
2
|
|
|
3
|
+
## 9.6.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- auth0**v2_users_by_email**GET**fetch:
|
|
8
|
+
auth0**v2_users_by_email**GET**fetch2:
|
|
9
|
+
|
|
10
|
+
fix: implementation
|
|
11
|
+
|
|
12
|
+
## 9.6.3
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- @ctx-core/env: ^17.2.107 -> ^17.2.108
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
- @ctx-core/auth0@38.7.2
|
|
19
|
+
|
|
20
|
+
## 9.6.2
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- Updated dependencies
|
|
25
|
+
- Updated dependencies
|
|
26
|
+
- @ctx-core/nanostores@4.2.7
|
|
27
|
+
- @ctx-core/auth0@38.7.1
|
|
28
|
+
|
|
29
|
+
## 9.6.1
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- @ctx-core/auth0: ^38.6.0 -> ^38.7.0
|
|
34
|
+
|
|
3
35
|
## 9.6.0
|
|
4
36
|
|
|
5
37
|
### Minor Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ctx-core/auth0-management",
|
|
3
|
-
"version": "9.6.
|
|
3
|
+
"version": "9.6.4",
|
|
4
4
|
"description": "ctx-core auth0 management api",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ctx-core",
|
|
@@ -28,12 +28,11 @@
|
|
|
28
28
|
"getAll-client-grants-auth0": "./bin/getAll-client-grants-auth0.mjs"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@ctx-core/auth0": "^38.
|
|
32
|
-
"@ctx-core/env": "^17.2.
|
|
31
|
+
"@ctx-core/auth0": "^38.7.2",
|
|
32
|
+
"@ctx-core/env": "^17.2.108",
|
|
33
33
|
"@ctx-core/error": "^12.3.36",
|
|
34
34
|
"@ctx-core/fetch": "^12.11.0",
|
|
35
|
-
"@ctx-core/
|
|
36
|
-
"@ctx-core/nanostores": "4.2.6",
|
|
35
|
+
"@ctx-core/nanostores": "4.2.7",
|
|
37
36
|
"@ctx-core/object": "^28.0.1",
|
|
38
37
|
"@ctx-core/uri": "^12.4.48",
|
|
39
38
|
"auth0": "^3.4.0"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AUTH0_CLIENT_ID_, AUTH0_DOMAIN_, header__access_token__verify } from '@ctx-core/auth0'
|
|
2
|
-
import {
|
|
2
|
+
import { fetch__template_pair_ } from '@ctx-core/fetch'
|
|
3
3
|
import { auth0_management__token__new } from '../auth0_management__token__new/index.js'
|
|
4
4
|
/** @typedef {import('@ctx-core/fetch').response_pair_T}response_pair_T */
|
|
5
5
|
/** @typedef {import('@ctx-core/object').Ctx}Ctx */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AUTH0_DOMAIN_, header__access_token__verify } from '@ctx-core/auth0'
|
|
2
|
-
import {
|
|
2
|
+
import { fetch__template_pair_ } from '@ctx-core/fetch'
|
|
3
3
|
import { query_str_ } from '@ctx-core/uri'
|
|
4
4
|
import { auth0_management__token__new } from '../auth0_management__token__new/index.js'
|
|
5
5
|
/** @typedef {import('@ctx-core/fetch').response_pair_T}response_pair_T */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AUTH0_DOMAIN_, header__access_token__verify } from '@ctx-core/auth0'
|
|
2
|
-
import {
|
|
2
|
+
import { fetch__template_pair_ } from '@ctx-core/fetch'
|
|
3
3
|
import { auth0_management__token__new } from '../auth0_management__token__new/index.js'
|
|
4
4
|
/** @typedef {import('@ctx-core/object').Ctx}Ctx */
|
|
5
5
|
/** @typedef {import('auth0').User}User */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AUTH0_DOMAIN_, header__access_token__verify } from '@ctx-core/auth0'
|
|
2
|
-
import {
|
|
2
|
+
import { fetch__template_pair_ } from '@ctx-core/fetch'
|
|
3
3
|
import {
|
|
4
4
|
auth0_management__token__new
|
|
5
5
|
} from '../auth0_management__token__new/index.js'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AUTH0_DOMAIN_, header__access_token__verify } from '@ctx-core/auth0'
|
|
2
|
-
import {
|
|
2
|
+
import { fetch__template_pair_ } from '@ctx-core/fetch'
|
|
3
3
|
import { auth0_management__token__new } from '../auth0_management__token__new/index.js'
|
|
4
4
|
/** @typedef {import('@ctx-core/object').Ctx}Ctx */
|
|
5
5
|
/** @type {import('auth0-js').Auth0UserProfile}Auth0UserProfile */
|
|
@@ -19,16 +19,13 @@ export const [
|
|
|
19
19
|
const auth0__token = await auth0_management__token__new(ctx)
|
|
20
20
|
const authorization = header__access_token__verify(auth0__token)
|
|
21
21
|
const url = `https://${AUTH0_DOMAIN}/api/v2/users-by-email?email=${encodeURIComponent(email)}`
|
|
22
|
-
|
|
22
|
+
return fetch(url, {
|
|
23
23
|
method: 'GET',
|
|
24
24
|
headers: {
|
|
25
25
|
'Content-Type': 'application/json',
|
|
26
26
|
authorization
|
|
27
27
|
}
|
|
28
28
|
})
|
|
29
|
-
/** @type {Auth0UserProfile[]} */
|
|
30
|
-
const auth0_user_profile_a = await res.json()
|
|
31
|
-
return [auth0_user_profile_a, res]
|
|
32
29
|
}
|
|
33
30
|
)
|
|
34
31
|
export {
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { AUTH0_DOMAIN__set } from '@ctx-core/auth0'
|
|
2
|
+
import { ctx_ } from '@ctx-core/object'
|
|
3
|
+
import { type Auth0UserProfile } from 'auth0-js'
|
|
4
|
+
import { restore, stub } from 'sinon'
|
|
5
|
+
import { test } from 'uvu'
|
|
6
|
+
import { equal } from 'uvu/assert'
|
|
7
|
+
import {
|
|
8
|
+
auth0__v2_users_by_email__GET__fetch,
|
|
9
|
+
auth0__v2_users_by_email__GET__fetch2,
|
|
10
|
+
auth0_management__init
|
|
11
|
+
} from '../index.js'
|
|
12
|
+
test.after.each(()=>{
|
|
13
|
+
restore()
|
|
14
|
+
})
|
|
15
|
+
test('auth0__v2_users_by_email__GET__fetch', async ()=>{
|
|
16
|
+
const ctx = ctx_()
|
|
17
|
+
AUTH0_DOMAIN__set(ctx, 'myapp.auth0.com')
|
|
18
|
+
auth0_management__init(ctx, {
|
|
19
|
+
AUTH0_MANAGEMENT_ID: 'AUTH0_MANAGEMENT_ID',
|
|
20
|
+
AUTH0_MANAGEMENT_SECRET: 'AUTH0_MANAGEMENT_SECRET'
|
|
21
|
+
})
|
|
22
|
+
const user_a = user_a_()
|
|
23
|
+
fetch__users_by_email__stub(user_a)
|
|
24
|
+
const response = await auth0__v2_users_by_email__GET__fetch(ctx, {
|
|
25
|
+
email: 'john.doe@gmail.com'
|
|
26
|
+
})
|
|
27
|
+
equal(await response.json(), user_a)
|
|
28
|
+
equal(response.status, 200)
|
|
29
|
+
})
|
|
30
|
+
test('auth0__v2_users_by_email__GET__fetch2', async ()=>{
|
|
31
|
+
const ctx = ctx_()
|
|
32
|
+
AUTH0_DOMAIN__set(ctx, 'myapp.auth0.com')
|
|
33
|
+
auth0_management__init(ctx, {
|
|
34
|
+
AUTH0_MANAGEMENT_ID: 'AUTH0_MANAGEMENT_ID',
|
|
35
|
+
AUTH0_MANAGEMENT_SECRET: 'AUTH0_MANAGEMENT_SECRET'
|
|
36
|
+
})
|
|
37
|
+
const user_a = user_a_()
|
|
38
|
+
fetch__users_by_email__stub(user_a)
|
|
39
|
+
const [payload, response] = await auth0__v2_users_by_email__GET__fetch2(ctx, {
|
|
40
|
+
email: 'john.doe@gmail.com'
|
|
41
|
+
})
|
|
42
|
+
equal(payload, user_a)
|
|
43
|
+
equal(response.status, 200)
|
|
44
|
+
})
|
|
45
|
+
test.run()
|
|
46
|
+
function fetch__users_by_email__stub(user_a:Auth0UserProfile[]) {
|
|
47
|
+
const fetch = stub(globalThis, 'fetch')
|
|
48
|
+
fetch
|
|
49
|
+
.withArgs('https://myapp.auth0.com/oauth/token', {
|
|
50
|
+
method: 'POST',
|
|
51
|
+
headers: { 'Content-Type': 'application/json' },
|
|
52
|
+
body: JSON.stringify({
|
|
53
|
+
grant_type: 'client_credentials',
|
|
54
|
+
client_id: 'AUTH0_MANAGEMENT_ID',
|
|
55
|
+
client_secret: 'AUTH0_MANAGEMENT_SECRET',
|
|
56
|
+
audience: 'https://myapp.auth0.com/api/v2/',
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
.resolves(new Response(JSON.stringify({
|
|
60
|
+
access_token: 'access_token',
|
|
61
|
+
token_type: 'Bearer',
|
|
62
|
+
}), {
|
|
63
|
+
status: 200,
|
|
64
|
+
headers: {
|
|
65
|
+
'Content-Type': 'application/json'
|
|
66
|
+
}
|
|
67
|
+
}))
|
|
68
|
+
fetch
|
|
69
|
+
.withArgs('https://myapp.auth0.com/api/v2/users-by-email?email=john.doe%40gmail.com', {
|
|
70
|
+
'method': 'GET',
|
|
71
|
+
'headers': {
|
|
72
|
+
'Content-Type': 'application/json',
|
|
73
|
+
'authorization': 'Bearer access_token'
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
.resolves(new Response(JSON.stringify(user_a), {
|
|
77
|
+
status: 200,
|
|
78
|
+
headers: {
|
|
79
|
+
'Content-Type': 'application/json'
|
|
80
|
+
}
|
|
81
|
+
}))
|
|
82
|
+
}
|
|
83
|
+
function user_a_():Auth0UserProfile[] {
|
|
84
|
+
return [
|
|
85
|
+
{
|
|
86
|
+
'user_id': 'auth0|507f1f77bcf86cd799439020',
|
|
87
|
+
'email': 'john.doe@gmail.com',
|
|
88
|
+
'email_verified': false,
|
|
89
|
+
'username': 'johndoe',
|
|
90
|
+
'created_at': '',
|
|
91
|
+
'updated_at': '',
|
|
92
|
+
'identities': [
|
|
93
|
+
{
|
|
94
|
+
'connection': 'Initial-Connection',
|
|
95
|
+
'user_id': '507f1f77bcf86cd799439020',
|
|
96
|
+
'provider': 'auth0',
|
|
97
|
+
'isSocial': false
|
|
98
|
+
}
|
|
99
|
+
],
|
|
100
|
+
'app_metadata': {},
|
|
101
|
+
'user_metadata': {},
|
|
102
|
+
'picture': '',
|
|
103
|
+
'name': '',
|
|
104
|
+
'nickname': '',
|
|
105
|
+
'given_name': '',
|
|
106
|
+
'family_name': ''
|
|
107
|
+
} as Auth0UserProfile
|
|
108
|
+
]
|
|
109
|
+
}
|
|
@@ -2,40 +2,43 @@ import { AUTH0_DOMAIN__set } from '@ctx-core/auth0'
|
|
|
2
2
|
import { ctx_ } from '@ctx-core/object'
|
|
3
3
|
import { restore, stub } from 'sinon'
|
|
4
4
|
import { test } from 'uvu'
|
|
5
|
-
import { equal
|
|
6
|
-
import {
|
|
7
|
-
import { AUTH0_MANAGEMENT_SECRET__set } from '../AUTH0_MANAGEMENT_SECRET$_/index.js'
|
|
8
|
-
import { auth0_management__token__new } from './index.js'
|
|
5
|
+
import { equal } from 'uvu/assert'
|
|
6
|
+
import { auth0_management__init, auth0_management__token__new } from '../index.js'
|
|
9
7
|
test.after.each(()=>restore())
|
|
10
8
|
test('auth0_management__token__new|error', async ()=>{
|
|
11
9
|
const ctx = ctx_()
|
|
12
10
|
AUTH0_DOMAIN__set(ctx, 'myapp.auth0.com')
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
headers: { 'Content-Type': 'application/json' },
|
|
19
|
-
body: JSON.stringify({
|
|
20
|
-
grant_type: 'client_credentials',
|
|
21
|
-
client_id: 'AUTH0_MANAGEMENT_ID',
|
|
22
|
-
client_secret: 'AUTH0_MANAGEMENT_SECRET',
|
|
23
|
-
audience: 'https://myapp.auth0.com/api/v2/',
|
|
24
|
-
})
|
|
25
|
-
})
|
|
26
|
-
.resolves(new Response(JSON.stringify({
|
|
27
|
-
error: 'security error',
|
|
28
|
-
error_description: 'invalid credentials'
|
|
29
|
-
}), {
|
|
30
|
-
status: 403,
|
|
31
|
-
headers: {
|
|
32
|
-
'Content-Type': 'application/json',
|
|
33
|
-
}
|
|
34
|
-
}))
|
|
11
|
+
auth0_management__init(ctx, {
|
|
12
|
+
AUTH0_MANAGEMENT_ID: 'AUTH0_MANAGEMENT_ID',
|
|
13
|
+
AUTH0_MANAGEMENT_SECRET: 'AUTH0_MANAGEMENT_SECRET'
|
|
14
|
+
})
|
|
15
|
+
fetch__oauth_token__stub()
|
|
35
16
|
let err
|
|
36
17
|
await auth0_management__token__new(ctx)
|
|
37
18
|
.catch($err=>err = $err)
|
|
38
19
|
equal(!!err, true)
|
|
39
20
|
equal(err.message, 'security error: invalid credentials')
|
|
21
|
+
function fetch__oauth_token__stub() {
|
|
22
|
+
stub(globalThis, 'fetch')
|
|
23
|
+
.withArgs('https://myapp.auth0.com/oauth/token', {
|
|
24
|
+
method: 'POST',
|
|
25
|
+
headers: { 'Content-Type': 'application/json' },
|
|
26
|
+
body: JSON.stringify({
|
|
27
|
+
grant_type: 'client_credentials',
|
|
28
|
+
client_id: 'AUTH0_MANAGEMENT_ID',
|
|
29
|
+
client_secret: 'AUTH0_MANAGEMENT_SECRET',
|
|
30
|
+
audience: 'https://myapp.auth0.com/api/v2/',
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
.resolves(new Response(JSON.stringify({
|
|
34
|
+
error: 'security error',
|
|
35
|
+
error_description: 'invalid credentials'
|
|
36
|
+
}), {
|
|
37
|
+
status: 403,
|
|
38
|
+
headers: {
|
|
39
|
+
'Content-Type': 'application/json',
|
|
40
|
+
}
|
|
41
|
+
}))
|
|
42
|
+
}
|
|
40
43
|
})
|
|
41
44
|
test.run()
|