@kubun/provider-google 0.15.0 → 0.17.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.
package/lib/index.d.ts CHANGED
@@ -1,7 +1,15 @@
1
- import type { OAuthProviderDefinition } from '@kubun/credential-types';
1
+ import type { OAuthProviderDefinition } from '@kokuin/oauth';
2
+ export declare const googleAuthorizationParams: Record<string, string>;
2
3
  type CreateGoogleProviderParams = {
4
+ mode: 'confidential';
3
5
  clientID: string;
4
6
  clientSecret: string;
7
+ } | {
8
+ mode: 'native';
9
+ clientID: string;
10
+ clientSecret?: string;
11
+ };
12
+ export declare function createGoogleProvider(params: CreateGoogleProviderParams): OAuthProviderDefinition & {
13
+ authorizationParams?: Record<string, string>;
5
14
  };
6
- export declare function createGoogleProvider(params: CreateGoogleProviderParams): OAuthProviderDefinition;
7
15
  export {};
package/lib/index.js CHANGED
@@ -1,11 +1,18 @@
1
+ export const googleAuthorizationParams = {
2
+ // Offline access requests a refresh token (issuance stays provider-dependent);
3
+ // consent keeps that guarantee for repeat authorizations. select_account forces
4
+ // the account chooser, avoiding the multi-account authuser dead-end.
5
+ access_type: 'offline',
6
+ prompt: 'select_account consent'
7
+ };
1
8
  export function createGoogleProvider(params) {
2
9
  if (!params.clientID) {
3
10
  throw new Error('Google provider requires a non-empty clientID');
4
11
  }
5
- if (!params.clientSecret) {
6
- throw new Error('Google provider requires a non-empty clientSecret');
12
+ if (params.mode === 'confidential' && !params.clientSecret) {
13
+ throw new Error('A confidential Google provider requires a non-empty clientSecret');
7
14
  }
8
- return {
15
+ const base = {
9
16
  name: 'google',
10
17
  authorizationEndpoint: 'https://accounts.google.com/o/oauth2/v2/auth',
11
18
  tokenEndpoint: 'https://oauth2.googleapis.com/token',
@@ -14,7 +21,19 @@ export function createGoogleProvider(params) {
14
21
  'profile',
15
22
  'email'
16
23
  ],
24
+ authorizationParams: googleAuthorizationParams
25
+ };
26
+ return params.mode === 'confidential' ? {
27
+ ...base,
28
+ mode: 'confidential',
17
29
  clientID: params.clientID,
18
30
  clientSecret: params.clientSecret
31
+ } : {
32
+ ...base,
33
+ mode: 'native',
34
+ clientID: params.clientID,
35
+ ...params.clientSecret ? {
36
+ clientSecret: params.clientSecret
37
+ } : {}
19
38
  };
20
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/provider-google",
3
- "version": "0.15.0",
3
+ "version": "0.17.0",
4
4
  "keywords": [],
5
5
  "license": "see LICENSE.md",
6
6
  "sideEffects": false,
@@ -15,7 +15,7 @@
15
15
  "LICENSE.md"
16
16
  ],
17
17
  "dependencies": {
18
- "@kubun/credential-types": "^0.15.0"
18
+ "@kokuin/oauth": "^0.1.0"
19
19
  },
20
20
  "publishConfig": {
21
21
  "access": "public"
@@ -23,8 +23,8 @@
23
23
  "scripts": {
24
24
  "build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
25
25
  "build:clean": "del lib",
26
- "build:js": "swc src -d ./lib --config-file ../../node_modules/@kigu/dev/swc.json --strip-leading-paths",
27
- "build:types": "tsc --emitDeclarationOnly --skipLibCheck",
26
+ "build:js": "del 'lib/**/*.js' && swc src -d ./lib --config-file ../../node_modules/@kigu/dev/swc.json --strip-leading-paths",
27
+ "build:types": "del 'lib/**/*.d.ts' 'lib/**/*.d.ts.map' && tsc --emitDeclarationOnly --skipLibCheck",
28
28
  "build:types:ci": "tsc --emitDeclarationOnly --declarationMap false",
29
29
  "test": "pnpm run test:types && pnpm run test:unit",
30
30
  "test:types": "tsc --noEmit -p tsconfig.test.json",