@webda/google-auth 4.0.0-beta.2 → 4.0.0-beta.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/webda.module.json CHANGED
@@ -1,46 +1,180 @@
1
1
  {
2
+ "$schema": "https://webda.io/schemas/webda.module.v4.json",
2
3
  "beans": {},
3
4
  "deployers": {},
4
5
  "moddas": {
5
- "Webda/GoogleAuthentication": "lib/google-auth:default"
6
- },
7
- "models": {
8
- "graph": {},
9
- "tree": {},
10
- "plurals": {},
11
- "list": {},
12
- "reflections": {}
6
+ "Webda/GoogleAuthentication": {
7
+ "Import": "lib/google-auth.service:GoogleAuthentication",
8
+ "Schema": {
9
+ "$schema": "http://json-schema.org/draft-07/schema#",
10
+ "additionalProperties": false,
11
+ "definitions": {
12
+ "OAuthRedirects": {
13
+ "additionalProperties": false,
14
+ "description": "Browser redirects of the OAuth callback",
15
+ "properties": {
16
+ "failure": {
17
+ "description": "Where a failed login or callback lands, with `?reason=<CODE>` (required)",
18
+ "type": "string"
19
+ },
20
+ "success": {
21
+ "default": "/",
22
+ "description": "Where a successful login lands when the login did not carry an allowed `redirect` parameter",
23
+ "type": "string"
24
+ }
25
+ },
26
+ "type": "object"
27
+ },
28
+ "Record<string, any>": {
29
+ "additionalProperties": {},
30
+ "description": "Construct a type with a set of properties K of type T",
31
+ "type": "object"
32
+ }
33
+ },
34
+ "description": "Google login parameters\nhttps://developers.google.com/identity/protocols/oauth2/openid-connect",
35
+ "properties": {
36
+ "access_type": {
37
+ "default": "online",
38
+ "description": "Type of access: \"offline\" also returns a refresh token (stored encrypted in the ident tokens)",
39
+ "enum": [
40
+ "online",
41
+ "offline"
42
+ ],
43
+ "type": "string"
44
+ },
45
+ "allowedEmailDomains": {
46
+ "description": "Only these email domains may use this provider (see ProviderEmailPolicy)",
47
+ "items": {
48
+ "type": "string"
49
+ },
50
+ "type": "array"
51
+ },
52
+ "audiences": {
53
+ "default": [],
54
+ "description": "Other client ids whose ID tokens `Auth.Google.Token` accepts (for example Android/iOS client ids)",
55
+ "items": {
56
+ "type": "string"
57
+ },
58
+ "type": "array"
59
+ },
60
+ "auth_options": {
61
+ "$ref": "#/definitions/Record%3Cstring%2C%20any%3E",
62
+ "description": "Additional authorization url parameters (for example `prompt`, `login_hint`); cannot override `state`,\n`redirect_uri`, `scope`, `access_type`, `response_type`, `code_challenge*`, `nonce` nor `hd`\nSee https://developers.google.com/identity/protocols/oauth2/openid-connect#authenticationuriparameters"
63
+ },
64
+ "authorized_uris": {
65
+ "default": [],
66
+ "description": "Allowed post-login targets for the `redirect` query parameter of the login route: absolute http(s) urls, a\ntarget matches when it has the same origin and its path is the listed path or below it",
67
+ "items": {
68
+ "type": "string"
69
+ },
70
+ "type": "array"
71
+ },
72
+ "client_id": {
73
+ "description": "Google OAuth client id (web application)",
74
+ "type": "string"
75
+ },
76
+ "client_secret": {
77
+ "description": "Google OAuth client secret",
78
+ "type": "string"
79
+ },
80
+ "hostedDomain": {
81
+ "description": "Only accept Google Workspace accounts of this domain (the `hd` claim of the ID token); also sent as a hint to\nthe account chooser",
82
+ "type": "string"
83
+ },
84
+ "redirect_uri": {
85
+ "default": "\"<absolute url of the request>/callback\"; set it explicitly behind a proxy",
86
+ "description": "Callback url registered at the provider",
87
+ "type": "string"
88
+ },
89
+ "redirects": {
90
+ "$ref": "#/definitions/OAuthRedirects",
91
+ "description": "Browser redirects of the callback"
92
+ },
93
+ "scope": {
94
+ "default": [
95
+ "openid",
96
+ "email",
97
+ "profile"
98
+ ],
99
+ "description": "Scopes requested from Google",
100
+ "items": {
101
+ "type": "string"
102
+ },
103
+ "type": "array"
104
+ },
105
+ "trustEmailVerification": {
106
+ "anyOf": [
107
+ {
108
+ "items": {
109
+ "type": "string"
110
+ },
111
+ "type": "array"
112
+ },
113
+ {
114
+ "type": "boolean"
115
+ }
116
+ ],
117
+ "description": "Whether the verification of the email is believed (see ProviderEmailPolicy)"
118
+ },
119
+ "type": {
120
+ "description": "Type of the service",
121
+ "type": "string"
122
+ },
123
+ "url": {
124
+ "default": "/auth/<providerName>",
125
+ "description": "Route prefix of the login (`<url>`) and callback (`<url>/callback`) routes",
126
+ "type": "string"
127
+ },
128
+ "openapi": {
129
+ "type": "object",
130
+ "additionalProperties": true
131
+ }
132
+ },
133
+ "required": [
134
+ "client_id",
135
+ "client_secret",
136
+ "type"
137
+ ],
138
+ "type": "object",
139
+ "title": "GoogleAuthentication"
140
+ },
141
+ "Configuration": "lib/google-auth.service:GoogleParameters"
142
+ }
13
143
  },
144
+ "models": {},
14
145
  "schemas": {
15
146
  "Webda/BinaryFile": {
16
- "type": "object",
147
+ "$schema": "http://json-schema.org/draft-07/schema#",
148
+ "WebdaSchema": true,
149
+ "additionalProperties": false,
150
+ "description": "Represent a file to store",
17
151
  "properties": {
18
- "hash": {
19
- "type": "string",
20
- "description": "Will be computed by the service\n\nhash of the content"
21
- },
22
152
  "challenge": {
23
- "type": "string",
24
- "description": "Will be computed by the service\n\nhash of the content prefixed by 'WEBDA'"
153
+ "description": "Will be computed by the service\n\nhash of the content prefixed by 'WEBDA'",
154
+ "type": "string"
25
155
  },
26
- "size": {
27
- "type": "number",
28
- "description": "Size of the binary"
156
+ "hash": {
157
+ "description": "Will be computed by the service\n\nhash of the content",
158
+ "type": "string"
29
159
  },
30
- "name": {
31
- "type": "string",
32
- "description": "Current name"
160
+ "metadata": {
161
+ "description": "Metadatas stored along with the binary"
33
162
  },
34
163
  "mimetype": {
35
- "type": "string",
36
- "description": "Mimetype of the binary"
164
+ "description": "Mimetype of the binary",
165
+ "type": "string"
37
166
  },
38
- "metadata": {
39
- "description": "Metadatas stored along with the binary"
167
+ "name": {
168
+ "description": "Current name",
169
+ "type": "string"
40
170
  },
41
171
  "originalname": {
42
- "type": "string",
43
- "description": "Original name"
172
+ "description": "Original name",
173
+ "type": "string"
174
+ },
175
+ "size": {
176
+ "description": "Size of the binary",
177
+ "type": "number"
44
178
  }
45
179
  },
46
180
  "required": [
@@ -48,120 +182,34 @@
48
182
  "name",
49
183
  "size"
50
184
  ],
51
- "description": "Represent a file to store",
52
- "$schema": "http://json-schema.org/draft-07/schema#",
185
+ "type": "object",
53
186
  "title": "BinaryFile"
54
187
  },
55
- "Webda/GoogleAuthentication": {
56
- "type": "object",
188
+ "Webda/OAuthTokenRequest": {
189
+ "$schema": "http://json-schema.org/draft-07/schema#",
190
+ "WebdaSchema": true,
191
+ "additionalProperties": false,
192
+ "definitions": {
193
+ "OAuthTokens": {
194
+ "additionalProperties": {},
195
+ "description": "Credentials as returned by an OAuth token endpoint (google-auth-library `Credentials` shape): `id_token`,\n`access_token`, `refresh_token`, `expiry_date`, `token_type`, `scope`... Values are not typed by the schema\n(providers send nulls); providers check what they use.",
196
+ "type": "object"
197
+ }
198
+ },
199
+ "description": "Input of the `Auth.<Provider>.Token` operations: `token`, or the provider credentials `tokens`",
57
200
  "properties": {
58
- "type": {
59
- "type": "string",
60
- "description": "Type of the service"
61
- },
62
- "url": {
63
- "type": "string",
64
- "description": "URL to use for expose\n\nThe default value varying based on implementation It should by default be the provider name in lowercase"
201
+ "token": {
202
+ "description": "Token issued by the provider to the client (an ID token for OpenID Connect providers)",
203
+ "type": "string"
65
204
  },
66
- "scope": {
67
- "type": "array",
68
- "items": {
69
- "type": "string"
70
- },
71
- "description": "Scope to request on OAuth flow"
72
- },
73
- "exposeScope": {
74
- "type": "boolean",
75
- "description": "If set to true it will add a ${url}/scope So client can anticipate the requested scope\n\nThis is useful when using the client api to generate token. This way the service can request the wanted scope",
76
- "default": false
77
- },
78
- "authorized_uris": {
79
- "type": "array",
80
- "items": {
81
- "type": "string"
82
- },
83
- "description": "List of URIs authorized for redirect post authorization",
84
- "default": []
85
- },
86
- "redirect_uri": {
87
- "type": "string",
88
- "description": "Default redirect_uri",
89
- "default": "${url}/callback"
90
- },
91
- "no_referer": {
92
- "type": "boolean",
93
- "description": "Allow direct connection without a referer",
94
- "default": false
95
- },
96
- "authenticationService": {
97
- "type": "string",
98
- "description": "Name of the authentication service to use if exist",
99
- "default": "Authentication"
100
- },
101
- "client_id": {
102
- "type": "string",
103
- "description": "Google Auth Client id"
104
- },
105
- "client_secret": {
106
- "type": "string",
107
- "description": "Google Auth Client secret"
108
- },
109
- "project_id": {
110
- "type": "string",
111
- "description": "Google Project ID"
112
- },
113
- "access_type": {
114
- "type": "string",
115
- "enum": [
116
- "online",
117
- "offline"
118
- ],
119
- "description": "Type of access for Google token\n\nonline by default"
120
- },
121
- "auth_options": {},
122
- "redirects": {
123
- "type": "object",
124
- "properties": {
125
- "use_referer": {
126
- "type": "boolean"
127
- },
128
- "whitelist": {
129
- "type": "array",
130
- "items": {
131
- "type": "string"
132
- }
133
- },
134
- "defaults": {
135
- "type": "object",
136
- "additionalProperties": {
137
- "type": "string"
138
- }
139
- }
140
- },
141
- "required": [
142
- "use_referer",
143
- "whitelist",
144
- "defaults"
145
- ]
146
- },
147
- "openapi": {
148
- "type": "object",
149
- "additionalProperties": true
205
+ "tokens": {
206
+ "$ref": "#/definitions/OAuthTokens",
207
+ "description": "Credentials obtained by the client from the provider (v3 body; its `id_token` is verified)"
150
208
  }
151
209
  },
152
- "required": [
153
- "authenticationService",
154
- "client_id",
155
- "client_secret",
156
- "exposeScope",
157
- "no_referer",
158
- "redirects",
159
- "scope",
160
- "type"
161
- ],
162
- "description": "Credentials to manage Google Auth https://developers.google.com/identity/protocols/oauth2",
163
- "$schema": "http://json-schema.org/draft-07/schema#",
164
- "title": "GoogleAuthentication"
210
+ "type": "object",
211
+ "title": "OAuthTokenRequest"
165
212
  }
166
- }
213
+ },
214
+ "behaviors": {}
167
215
  }
@@ -1,125 +0,0 @@
1
- import { OAuthEvents, OAuthService, OAuthServiceParameters, RequestFilter, WebContext } from "@webda/core";
2
- import { Credentials, OAuth2Client } from "google-auth-library";
3
- export interface EventGoogleOAuthToken {
4
- /**
5
- * Tokens retrieved from Google
6
- */
7
- tokens: Credentials;
8
- /**
9
- * Request context
10
- */
11
- context: WebContext;
12
- }
13
- /**
14
- * Credentials to manage Google Auth
15
- * https://developers.google.com/identity/protocols/oauth2
16
- */
17
- export declare class GoogleParameters extends OAuthServiceParameters {
18
- /**
19
- * Google Auth Client id
20
- */
21
- client_id: string;
22
- /**
23
- * Google Auth Client secret
24
- */
25
- client_secret: string;
26
- /**
27
- * Google Project ID
28
- */
29
- project_id?: string;
30
- /**
31
- * Type of access for Google token
32
- *
33
- * online by default
34
- */
35
- access_type?: "online" | "offline";
36
- auth_options?: any;
37
- redirects: {
38
- use_referer: boolean;
39
- whitelist: string[];
40
- defaults: {
41
- [key: string]: string;
42
- };
43
- };
44
- constructor(params: any);
45
- }
46
- type GoogleAuthEvents = OAuthEvents & {
47
- "GoogleAuth.Tokens": EventGoogleOAuthToken;
48
- };
49
- /**
50
- * Manage Google Authentication
51
- *
52
- * @WebdaModda
53
- */
54
- export default class GoogleAuthentication<T extends GoogleParameters = GoogleParameters> extends OAuthService<T, GoogleAuthEvents> implements RequestFilter<WebContext> {
55
- protected _client: OAuth2Client;
56
- /**
57
- * Return provider name
58
- * @returns
59
- */
60
- getName(): string;
61
- /**
62
- * Allow every accounts.google.
63
- */
64
- getCallbackReferer(): RegExp[];
65
- /**
66
- * Get OAuth callback query parameters
67
- * @returns
68
- */
69
- getCallbackQueryParams(): {
70
- name: string;
71
- required: boolean;
72
- }[];
73
- /**
74
- * Expose on /google by default
75
- */
76
- getDefaultUrl(): string;
77
- /**
78
- * We manage Google Auth Token
79
- */
80
- hasToken(): boolean;
81
- /**
82
- * @inheritdoc
83
- */
84
- loadParameters(params: any): GoogleParameters;
85
- /**
86
- *
87
- * @param redirect_uri
88
- * @param state
89
- */
90
- generateAuthUrl(redirect_uri: string, state: string, _ctx: WebContext): string;
91
- /**
92
- * Return a google oauth client
93
- * @param redirect_uri
94
- */
95
- getOAuthClient(redirect_uri?: string): OAuth2Client;
96
- /**
97
- * @inheritdoc
98
- */
99
- handleCallback(ctx: WebContext): Promise<{
100
- identId: any;
101
- profile: any;
102
- }>;
103
- /**
104
- * Retrieve the user profile based on the token
105
- * @param token
106
- * @returns
107
- */
108
- getUserInfo(token: string): Promise<import("google-auth-library").TokenPayload>;
109
- /**
110
- * Verify a Google Auth Token
111
- */
112
- handleToken(context: WebContext): Promise<{
113
- identId: string;
114
- profile: import("google-auth-library").TokenPayload;
115
- }>;
116
- /**
117
- * Retrieve Google Client
118
- *
119
- * Redirecting to the webbrowser for the OAuth validation
120
- * Store the token in user store afterwards
121
- */
122
- getLocalClient(token: Credentials, open: (url: string) => void, storeToken: (token: Credentials) => Promise<void>): Promise<OAuth2Client>;
123
- }
124
- export { GoogleAuthentication };
125
- //# sourceMappingURL=google-auth.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"google-auth.d.ts","sourceRoot":"","sources":["../src/google-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,YAAY,EACZ,sBAAsB,EAEtB,aAAa,EACb,UAAU,EAEX,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGhE,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,MAAM,EAAE,WAAW,CAAC;IACpB;;OAEG;IACH,OAAO,EAAE,UAAU,CAAC;CACrB;AAED;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,sBAAsB;IAC1D;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,WAAW,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAEnC,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,SAAS,EAAE;QAET,WAAW,EAAE,OAAO,CAAC;QAErB,SAAS,EAAE,MAAM,EAAE,CAAC;QAEpB,QAAQ,EAAE;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;SAAE,CA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