@owox/idp-protocol 0.4.0

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.
Files changed (46) hide show
  1. package/README.md +298 -0
  2. package/dist/index.d.ts +4 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +6 -0
  5. package/dist/middleware/index.d.ts +2 -0
  6. package/dist/middleware/index.d.ts.map +1 -0
  7. package/dist/middleware/index.js +1 -0
  8. package/dist/middleware/protocol-middleware.d.ts +99 -0
  9. package/dist/middleware/protocol-middleware.d.ts.map +1 -0
  10. package/dist/middleware/protocol-middleware.js +131 -0
  11. package/dist/providers/index.d.ts +2 -0
  12. package/dist/providers/index.d.ts.map +1 -0
  13. package/dist/providers/index.js +1 -0
  14. package/dist/providers/null-provider.d.ts +24 -0
  15. package/dist/providers/null-provider.d.ts.map +1 -0
  16. package/dist/providers/null-provider.js +58 -0
  17. package/dist/types/cli.d.ts +27 -0
  18. package/dist/types/cli.d.ts.map +1 -0
  19. package/dist/types/cli.js +1 -0
  20. package/dist/types/config.d.ts +14 -0
  21. package/dist/types/config.d.ts.map +1 -0
  22. package/dist/types/config.js +1 -0
  23. package/dist/types/errors.d.ts +33 -0
  24. package/dist/types/errors.d.ts.map +1 -0
  25. package/dist/types/errors.js +45 -0
  26. package/dist/types/index.d.ts +9 -0
  27. package/dist/types/index.d.ts.map +1 -0
  28. package/dist/types/index.js +13 -0
  29. package/dist/types/models.d.ts +24 -0
  30. package/dist/types/models.d.ts.map +1 -0
  31. package/dist/types/models.js +1 -0
  32. package/dist/types/provider.d.ts +63 -0
  33. package/dist/types/provider.d.ts.map +1 -0
  34. package/dist/types/provider.js +1 -0
  35. package/package.json +52 -0
  36. package/src/index.ts +8 -0
  37. package/src/middleware/index.ts +1 -0
  38. package/src/middleware/protocol-middleware.ts +178 -0
  39. package/src/providers/index.ts +1 -0
  40. package/src/providers/null-provider.ts +71 -0
  41. package/src/types/cli.ts +30 -0
  42. package/src/types/config.ts +14 -0
  43. package/src/types/errors.ts +49 -0
  44. package/src/types/index.ts +18 -0
  45. package/src/types/models.ts +28 -0
  46. package/src/types/provider.ts +72 -0
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The roles that are supported by the IDP.
3
+ */
4
+ export type Role = 'admin' | 'editor' | 'viewer';
5
+
6
+ /**
7
+ * Standardized token payload that all IDP implementations must return when introspecting their native tokens.
8
+ */
9
+ export interface Payload {
10
+ userId: string;
11
+ projectId: string;
12
+
13
+ email?: string;
14
+ fullName?: string;
15
+ avatar?: string;
16
+
17
+ roles?: Role[];
18
+
19
+ projectTitle?: string;
20
+ }
21
+
22
+ /**
23
+ * Authentication result from IDP callback
24
+ */
25
+ export interface AuthResult {
26
+ accessToken: string;
27
+ refreshToken?: string;
28
+ }
@@ -0,0 +1,72 @@
1
+ import { Payload, AuthResult } from './models.js';
2
+ import { NextFunction, Request, Response } from 'express';
3
+
4
+ /**
5
+ * Simplified IDP Provider interface.
6
+ */
7
+ export interface IdpProvider {
8
+ /**
9
+ * Sign in middleware. This method is used to handle the sign in request and use response to send the sign in response.
10
+ * <br/>
11
+ * If the IDP implementation does not support sign in, this method should call the `next()` function.
12
+ */
13
+ signInMiddleware(req: Request, res: Response, next: NextFunction): Promise<void | Response>;
14
+
15
+ /**
16
+ * Sign out middleware. This method is used to handle the sign out request and use response to send the sign out response.
17
+ * <br/>
18
+ * If the IDP implementation does not support sign out, this method should call the `next()` function.
19
+ */
20
+ signOutMiddleware(req: Request, res: Response, next: NextFunction): Promise<void | Response>;
21
+
22
+ /**
23
+ * Access token middleware. This method is used to handle the access token request and use response to send the access token response.
24
+ * <br/>
25
+ * If the IDP implementation does not support access token, this method should call the `next()` function.
26
+ */
27
+ accessTokenMiddleware(req: Request, res: Response, next: NextFunction): Promise<void | Response>;
28
+
29
+ /**
30
+ * User api middleware. This method is used to handle the user request and use response to send the user response.
31
+ * <br/>
32
+ * If the IDP implementation does not support user, this method should call the `next()` function.
33
+ */
34
+ userApiMiddleware(req: Request, res: Response, next: NextFunction): Promise<Response<Payload>>;
35
+
36
+ /**
37
+ * Introspect a token
38
+ * @param token - The token to introspect
39
+ * @returns The token payload
40
+ */
41
+ introspectToken(token: string): Promise<Payload | null>;
42
+
43
+ /**
44
+ * Parse a token
45
+ * @param token - The token to parse
46
+ * @returns The token payload
47
+ */
48
+ parseToken(token: string): Promise<Payload | null>;
49
+
50
+ /**
51
+ * Refresh a token
52
+ * @param refreshToken - The refresh token to use for the refresh
53
+ * @returns The authentication result
54
+ */
55
+ refreshToken(refreshToken: string): Promise<AuthResult>;
56
+
57
+ /**
58
+ * Revoke a token. In different IDP implementations, this may have different token types.
59
+ * @param token - The token to revoke
60
+ */
61
+ revokeToken(token: string): Promise<void>;
62
+
63
+ /**
64
+ * Initialize the IDP. Create resources, connect to databases, etc.
65
+ */
66
+ initialize(): Promise<void>;
67
+
68
+ /**
69
+ * Shutdown the IDP, close all connections and release resources
70
+ */
71
+ shutdown(): Promise<void>;
72
+ }