@sphereon/ssi-express-support 0.14.2-next.25

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 (48) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +25 -0
  3. package/dist/auth-utils.d.ts +19 -0
  4. package/dist/auth-utils.d.ts.map +1 -0
  5. package/dist/auth-utils.js +118 -0
  6. package/dist/auth-utils.js.map +1 -0
  7. package/dist/entra-id-auth.d.ts +10 -0
  8. package/dist/entra-id-auth.d.ts.map +1 -0
  9. package/dist/entra-id-auth.js +61 -0
  10. package/dist/entra-id-auth.js.map +1 -0
  11. package/dist/express-builders.d.ts +94 -0
  12. package/dist/express-builders.d.ts.map +1 -0
  13. package/dist/express-builders.js +269 -0
  14. package/dist/express-builders.js.map +1 -0
  15. package/dist/express-utils.d.ts +4 -0
  16. package/dist/express-utils.d.ts.map +1 -0
  17. package/dist/express-utils.js +34 -0
  18. package/dist/express-utils.js.map +1 -0
  19. package/dist/functions.d.ts +2 -0
  20. package/dist/functions.d.ts.map +1 -0
  21. package/dist/functions.js +11 -0
  22. package/dist/functions.js.map +1 -0
  23. package/dist/index.d.ts +8 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +27 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/openid-connect-auth.d.ts +10 -0
  28. package/dist/openid-connect-auth.d.ts.map +1 -0
  29. package/dist/openid-connect-auth.js +61 -0
  30. package/dist/openid-connect-auth.js.map +1 -0
  31. package/dist/static-bearer-auth.d.ts +34 -0
  32. package/dist/static-bearer-auth.d.ts.map +1 -0
  33. package/dist/static-bearer-auth.js +146 -0
  34. package/dist/static-bearer-auth.js.map +1 -0
  35. package/dist/types.d.ts +179 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/types.js +8 -0
  38. package/dist/types.js.map +1 -0
  39. package/package.json +70 -0
  40. package/src/auth-utils.ts +127 -0
  41. package/src/entra-id-auth.ts +47 -0
  42. package/src/express-builders.ts +320 -0
  43. package/src/express-utils.ts +30 -0
  44. package/src/functions.ts +6 -0
  45. package/src/index.ts +7 -0
  46. package/src/openid-connect-auth.ts +47 -0
  47. package/src/static-bearer-auth.ts +151 -0
  48. package/src/types.ts +192 -0
package/src/types.ts ADDED
@@ -0,0 +1,192 @@
1
+ import { Enforcer } from 'casbin'
2
+ import { Express, RequestHandler } from 'express'
3
+ import { ParamsDictionary } from 'express-serve-static-core'
4
+ import { Strategy } from 'passport'
5
+ import { ParsedQs } from 'qs'
6
+
7
+ export interface IExpressServerOpts {
8
+ port?: number // The port to listen on
9
+ cookieSigningKey?: string
10
+ hostname?: string // defaults to "0.0.0.0", meaning it will listen on all IP addresses. Can be an IP address or hostname
11
+ basePath?: string
12
+ existingExpress?: Express
13
+ listenCallback?: () => void
14
+ startListening?: boolean
15
+ // externalBaseUrl?: string // In case an external base URL needs to be exposed
16
+ }
17
+
18
+ export function hasEndpointOpts(opts: any) {
19
+ return 'endpointOpts' in opts && opts.endpointOpts
20
+ }
21
+
22
+ export type HasEndpointOpts = { endpointOpts?: IEndpointOpts & SingleEndpoints } & Record<string, any>
23
+
24
+ export type SingleEndpoints = Record<string, ISingleEndpointOpts | any>
25
+ export interface IEndpointOpts {
26
+ basePath?: string
27
+ globalAuth?: GenericAuthArgs
28
+ }
29
+ export interface ExpressSupport {
30
+ express: Express
31
+ port: number
32
+ hostname: string
33
+ userIsInRole?: string | string[]
34
+ startListening: boolean
35
+ enforcer?: Enforcer
36
+ start: (opts?: { disableErrorHandler?: boolean }) => Express
37
+ }
38
+
39
+ export interface ISingleEndpointOpts extends GenericAuthArgs {
40
+ endpoint?: EndpointArgs
41
+ enabled?: boolean
42
+ path?: string
43
+ disableGlobalAuth?: boolean
44
+ }
45
+
46
+ export interface GenericAuthArgs {
47
+ authentication?: {
48
+ enabled?: boolean
49
+ strategy?: string | string[] | Strategy
50
+ }
51
+ authorization?: {
52
+ enabled?: boolean
53
+ requireUserInRoles?: string | string[]
54
+ enforcer?: Enforcer
55
+ }
56
+ }
57
+
58
+ export interface EndpointArgs extends GenericAuthArgs {
59
+ resource?: string
60
+ operation?: string
61
+ handlers?: RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]
62
+ }
63
+
64
+ export interface BearerUser extends Express.User {
65
+ id: string | number
66
+ name?: string
67
+ token: string
68
+ }
69
+
70
+ export interface IStaticBearerVerifyOptions {
71
+ message?: string | undefined
72
+ scope: string | Array<string>
73
+ }
74
+
75
+ export interface IBaseStrategyOption {
76
+ identityMetadata: string
77
+ clientID: string
78
+ isB2C?: boolean | undefined
79
+ validateIssuer?: boolean | undefined
80
+ issuer?: string | string[] | undefined
81
+ loggingLevel?: 'info' | 'warn' | 'error' | undefined
82
+ loggingNoPII?: boolean | undefined
83
+ clockSkew?: number | undefined
84
+ }
85
+
86
+ export interface ITokenPayload {
87
+ /** An App ID URI. Identifies the intended recipient of the token. */
88
+ aud?: string | undefined
89
+ /** A security token service(STS) URI. Identifies the STS that constructs and returns the token,
90
+ * and the Azure AD tenant in which the user was authenticated.*/
91
+ iss?: string | undefined
92
+ /** The identity provider that authenticated the subject of the token*/
93
+ idp?: string | undefined
94
+ /** "Issued At" indicates when the authentication for this token occurred. */
95
+ iat?: number | undefined
96
+ /** The "nbf" (not before) claim identifies the time before which the JWT must not be accepted for processing. */
97
+ nbf?: number | undefined
98
+ /** The "exp" (expiration time) claim identifies the expiration time on or after which the JWT must not be accepted for processing. */
99
+ exp?: number | undefined
100
+ /** An internal claim used by Azure AD to record data for token reuse. */
101
+ aio?: string | undefined
102
+ /** Only present in v1.0 tokens. The "Authentication context class" claim. A value of "0" indicates the end-user authentication did not meet the requirements of ISO/IEC 29115. */
103
+ acr?: '0' | '1' | undefined
104
+ /** Only present in v1.0 tokens. Identifies how the subject of the token was authenticated. */
105
+ amr?: string[] | undefined
106
+ /** Only present in v1.0 tokens. GUID represents the application ID of the client using the token. */
107
+ appid?: string | undefined
108
+ /** Only present in v2.0 tokens. The application ID of the client using the token. */
109
+ azp?: string | undefined
110
+ /** Only present in v1.0 tokens. Indicates how the client was authenticated. For a public client, the value is "0".
111
+ * If client ID and client secret are used, the value is "1". If a client certificate was used for authentication, the value is "2". */
112
+ appidacr?: '0' | '1' | '2' | undefined
113
+ /** Only present in v2.0 tokens. Indicates how the client was authenticated.
114
+ * For a public client, the value is "0". If client ID and client secret are used, the value is "1". If a client certificate was used for authentication, the value is "2". */
115
+ azpacr?: '0' | '1' | '2' | undefined
116
+ /** Only present in v2.0 tokens. The primary username that represents the user. It could be an email address, phone number, or a generic username without a specified format */
117
+ preferred_username?: string | undefined
118
+ /** Provides a human-readable value that identifies the subject of the token.
119
+ * The value is not guaranteed to be unique, it is mutable, and it's designed to be used only for display purposes. The profile scope is required in order to receive this claim. */
120
+ name?: string | undefined
121
+ /** The set of scopes exposed by your application for which the client application has requested (and received) consent. */
122
+ scp?: string | undefined
123
+ /** The set of permissions exposed by your application that the requesting application has been given permission to call. */
124
+ roles?: string[] | undefined
125
+ /** Provides object IDs that represent the subject's group memberships. */
126
+ groups?: string | string[] | undefined
127
+ /** Denoting the user is in at least one group. */
128
+ hasgroups?: true | undefined
129
+ /** The principal about which the token asserts information, such as the user of an app. This value is immutable and cannot be reassigned or reused.
130
+ * It can be used to perform authorization checks safely, such as when the token is used to access a resource,
131
+ * and can be used as a key in database tables. Because the subject is always present in the tokens that Azure AD issues,
132
+ * we recommend using this value in a general-purpose authorization system. The subject is, however, a pairwise identifier - it is unique to a particular application ID. */
133
+ sub?: string | undefined
134
+ /** GUID represents a user. This ID uniquely identifies the user across applications. */
135
+ oid?: string | undefined
136
+ /** Represents the Azure AD tenant that the user is from. */
137
+ tid?: string | undefined
138
+ /** Only present in v1.0 tokens. Provides a human readable value that identifies the subject of the token. */
139
+ unique_name?: string | undefined
140
+ /** An internal claim used by Azure to revalidate tokens. */
141
+ uti?: string | undefined
142
+ /** An internal claim used by Azure to revalidate tokens. */
143
+ rh?: string | undefined
144
+ /** Indicates the version of the access token. */
145
+ ver?: '1.0' | '2.0' | undefined
146
+
147
+ /** v1.0 basic claims */
148
+
149
+ /** The IP address the user authenticated from. */
150
+ ipaddr?: string | undefined
151
+ /** In cases where the user has an on-premises authentication, this claim provides their SID. */
152
+ onprem_sid?: string | undefined
153
+ /** Indicates when the user's password expires. */
154
+ pwd_exp?: number | undefined
155
+ /** A URL where users can be sent to reset their password. */
156
+ pwd_url?: string | undefined
157
+ /** Signals if the client is logging in from the corporate network. If they aren't, the claim isn't included. */
158
+ in_corp?: string | undefined
159
+ /** An additional name for the user, separate from first or last name */
160
+ nickname?: string | undefined
161
+ /** Provides the last name, surname, or family name of the user as defined on the user object. */
162
+ family_name?: string | undefined
163
+ /** Provides the first or given name of the user, as set on the user object. */
164
+ given_name?: string | undefined
165
+ /** The username of the user. May be a phone number, email address, or unformatted string. */
166
+ upn?: string | undefined
167
+ }
168
+ export interface IBaseStrategyOption {
169
+ identityMetadata: string
170
+ clientID: string
171
+ isB2C?: boolean | undefined
172
+ validateIssuer?: boolean | undefined
173
+ issuer?: string | string[] | undefined
174
+ loggingLevel?: 'info' | 'warn' | 'error' | undefined
175
+ loggingNoPII?: boolean | undefined
176
+ clockSkew?: number | undefined
177
+ }
178
+
179
+ export interface IBearerStrategyOption extends IBaseStrategyOption {
180
+ audience?: string | string[] | undefined
181
+ policyName?: String | undefined
182
+ allowMultiAudiencesInToken?: boolean | undefined
183
+ scope?: string[] | undefined
184
+ }
185
+
186
+ export interface IBearerStrategyOptionWithRequest extends IBearerStrategyOption {
187
+ passReqToCallback: boolean
188
+ }
189
+ export type VerifyBearerFunction = (token: ITokenPayload, done: VerifyCallback) => void
190
+ export interface VerifyCallback {
191
+ (error: any, user?: any, info?: any): void
192
+ }