@flipdish/authorization 0.0.1 → 0.0.2-rc.1756734895
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/.openapi-generator/FILES +1 -0
- package/README.md +39 -39
- package/configuration.ts +1 -1
- package/dist/configuration.js +1 -1
- package/package.json +1 -1
package/.openapi-generator/FILES
CHANGED
package/README.md
CHANGED
|
@@ -7,11 +7,11 @@ Internally the package utilizes the [axios](https://github.com/axios/axios) as i
|
|
|
7
7
|
### Example code
|
|
8
8
|
|
|
9
9
|
```typescript
|
|
10
|
-
import { AuthorizationApi, Configuration, PermissionsApi, Permissions } from
|
|
11
|
-
import { describe, expect, test, it } from
|
|
10
|
+
import { AuthorizationApi, Configuration, PermissionsApi, Permissions } from '@flipdish/authorization';
|
|
11
|
+
import { describe, expect, test, it } from '@jest/globals';
|
|
12
12
|
|
|
13
|
-
const basePath
|
|
14
|
-
const configuration
|
|
13
|
+
const basePath = "https://api.flipdish.co/auth/";
|
|
14
|
+
const configuration = new Configuration({
|
|
15
15
|
basePath,
|
|
16
16
|
// to get the API key, you should follow these docs:
|
|
17
17
|
// https://developers.flipdish.com/docs/getting-started
|
|
@@ -21,14 +21,14 @@ const configuration = new Configuration({
|
|
|
21
21
|
// useDefaultUserAgent: true
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
const authorization
|
|
25
|
-
const permissions
|
|
24
|
+
const authorization = new AuthorizationApi(configuration);
|
|
25
|
+
const permissions = new PermissionsApi(configuration);
|
|
26
26
|
|
|
27
|
-
describe(
|
|
28
|
-
describe(
|
|
27
|
+
describe('Authorization Tests', () => {
|
|
28
|
+
describe('Authorization', () => {
|
|
29
29
|
|
|
30
|
-
test(
|
|
31
|
-
const permissionsResponse
|
|
30
|
+
test('List Permissions', async () => {
|
|
31
|
+
const permissionsResponse = await permissions.listPermissions();
|
|
32
32
|
expect(permissionsResponse.status).toBe(200);
|
|
33
33
|
expect(permissionsResponse.data.permissions).toBeDefined();
|
|
34
34
|
expect(permissionsResponse.data.permissions.length).toBeGreaterThan(0);
|
|
@@ -39,82 +39,82 @@ describe('Authorization Tests', () => {
|
|
|
39
39
|
expect(permissionsResponse.data.permissions).toContain(Permissions.EditAppAssets);
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
describe(
|
|
43
|
-
it(
|
|
44
|
-
const authorizationResponse
|
|
42
|
+
describe('Authenticate and Authorize', () => {
|
|
43
|
+
it('should authenticate and authorize with a valid FD-Authorization cookie', async () => {
|
|
44
|
+
const authorizationResponse = await authorization.authenticateAndAuthorize({
|
|
45
45
|
headers: {
|
|
46
|
-
|
|
46
|
+
'Cookie': `FD-Authorization=${process.env.FD_AUTH_COOKIE_PROD};`,
|
|
47
47
|
},
|
|
48
48
|
action: Permissions.AnyAuditLogs,
|
|
49
49
|
resource: {
|
|
50
|
-
id:
|
|
51
|
-
type:
|
|
50
|
+
id: "org12345",
|
|
51
|
+
type: "Org",
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
expect(authorizationResponse.status).toBe(200);
|
|
56
56
|
expect(authorizationResponse.data.authentication.authenticated).toBe(true);
|
|
57
|
-
expect(authorizationResponse.data.authentication.principal?.type).toBe(
|
|
58
|
-
expect(authorizationResponse.data.authentication.principal?.id).toBe(
|
|
57
|
+
expect(authorizationResponse.data.authentication.principal?.type).toBe("User");
|
|
58
|
+
expect(authorizationResponse.data.authentication.principal?.id).toBe("8147747");
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
it(
|
|
61
|
+
it('should not authenticate and authorize with an invalid FD-Authorization cookie', async () => {
|
|
62
62
|
try {
|
|
63
63
|
await authorization.authenticateAndAuthorize({
|
|
64
64
|
headers: {
|
|
65
|
-
|
|
65
|
+
'Cookie': `FD-Authorization=not-a-valid-cookie;`,
|
|
66
66
|
},
|
|
67
67
|
action: Permissions.AnyAuditLogs,
|
|
68
68
|
resource: {
|
|
69
|
-
id:
|
|
70
|
-
type:
|
|
69
|
+
id: "org12345",
|
|
70
|
+
type: "Org",
|
|
71
71
|
},
|
|
72
72
|
});
|
|
73
73
|
} catch (error: any) {
|
|
74
74
|
expect(error.response.status).toBe(401);
|
|
75
|
-
expect(error.response.data.message).toBe(
|
|
75
|
+
expect(error.response.data.message).toBe("Unauthenticated");
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
78
|
|
|
79
|
-
it(
|
|
80
|
-
const authorizationResponse
|
|
79
|
+
it('should authenticate and authorize with a valid Bearer token', async () => {
|
|
80
|
+
const authorizationResponse = await authorization.authenticateAndAuthorize({
|
|
81
81
|
headers: {
|
|
82
|
-
|
|
82
|
+
'Authorization': `Bearer ${process.env.FLIPDISH_BEARER_TOKEN_PROD}`,
|
|
83
83
|
},
|
|
84
84
|
action: Permissions.AnyAuditLogs,
|
|
85
85
|
resource: {
|
|
86
|
-
id:
|
|
87
|
-
type:
|
|
86
|
+
id: "org12345",
|
|
87
|
+
type: "Org",
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
90
|
|
|
91
91
|
expect(authorizationResponse.status).toBe(200);
|
|
92
92
|
expect(authorizationResponse.data.authentication.authenticated).toBe(true);
|
|
93
|
-
expect(authorizationResponse.data.authentication.principal?.type).toBe(
|
|
94
|
-
expect(authorizationResponse.data.authentication.principal?.id).toBe(
|
|
93
|
+
expect(authorizationResponse.data.authentication.principal?.type).toBe("User");
|
|
94
|
+
expect(authorizationResponse.data.authentication.principal?.id).toBe("8147747");
|
|
95
95
|
});
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
|
|
99
|
-
test(
|
|
100
|
-
let testPrincipal: any
|
|
101
|
-
id:
|
|
102
|
-
type:
|
|
99
|
+
test('Authorize', async () => {
|
|
100
|
+
let testPrincipal: any = {
|
|
101
|
+
id: "12345",
|
|
102
|
+
type: "User",
|
|
103
103
|
};
|
|
104
104
|
|
|
105
|
-
let testResource: any
|
|
106
|
-
id:
|
|
107
|
-
type:
|
|
105
|
+
let testResource: any = {
|
|
106
|
+
id: "org12345",
|
|
107
|
+
type: "Org",
|
|
108
108
|
};
|
|
109
109
|
|
|
110
|
-
const authorizationResponse
|
|
110
|
+
const authorizationResponse = await authorization.authorize({
|
|
111
111
|
principal: testPrincipal,
|
|
112
112
|
action: Permissions.AnyAuditLogs,
|
|
113
113
|
resource: testResource
|
|
114
114
|
});
|
|
115
115
|
expect(authorizationResponse.status).toBe(200);
|
|
116
116
|
expect(authorizationResponse.data.allowed).toBe(false);
|
|
117
|
-
expect(authorizationResponse.data.decision).toBe(
|
|
117
|
+
expect(authorizationResponse.data.decision).toBe("DENY");
|
|
118
118
|
});
|
|
119
119
|
});
|
|
120
120
|
});
|
package/configuration.ts
CHANGED
|
@@ -100,7 +100,7 @@ export class Configuration {
|
|
|
100
100
|
|
|
101
101
|
const extraHeaders = param.useDefaultUserAgent ? {} : {
|
|
102
102
|
headers: {
|
|
103
|
-
"user-agent": "Flipdish authorization typescript SDK / 0.0.
|
|
103
|
+
"user-agent": "Flipdish authorization typescript SDK / 0.0.2-rc.1756734895"
|
|
104
104
|
}
|
|
105
105
|
};
|
|
106
106
|
|
package/dist/configuration.js
CHANGED
|
@@ -36,7 +36,7 @@ var Configuration = /** @class */ (function () {
|
|
|
36
36
|
this.serverIndex = param.serverIndex;
|
|
37
37
|
var extraHeaders = param.useDefaultUserAgent ? {} : {
|
|
38
38
|
headers: {
|
|
39
|
-
"user-agent": "Flipdish authorization typescript SDK / 0.0.
|
|
39
|
+
"user-agent": "Flipdish authorization typescript SDK / 0.0.2-rc.1756734895"
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
this.baseOptions = __assign(__assign({}, extraHeaders), param.baseOptions);
|