google-oauth-lib 1.0.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 (54) hide show
  1. package/dist/base.d.ts +12 -0
  2. package/dist/base.d.ts.map +1 -0
  3. package/dist/base.js +26 -0
  4. package/dist/base.js.map +1 -0
  5. package/dist/index.d.ts +5 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +14 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/lib/oauth.d.ts +22 -0
  10. package/dist/lib/oauth.d.ts.map +1 -0
  11. package/dist/lib/oauth.js +70 -0
  12. package/dist/lib/oauth.js.map +1 -0
  13. package/dist/lib/user.d.ts +13 -0
  14. package/dist/lib/user.d.ts.map +1 -0
  15. package/dist/lib/user.js +50 -0
  16. package/dist/lib/user.js.map +1 -0
  17. package/dist/oauth.d.ts +22 -0
  18. package/dist/oauth.d.ts.map +1 -0
  19. package/dist/oauth.js +70 -0
  20. package/dist/oauth.js.map +1 -0
  21. package/dist/types/config.d.ts +22 -0
  22. package/dist/types/config.d.ts.map +1 -0
  23. package/dist/types/config.js +3 -0
  24. package/dist/types/config.js.map +1 -0
  25. package/dist/types/index.d.ts +13 -0
  26. package/dist/types/index.d.ts.map +1 -0
  27. package/dist/types/index.js +13 -0
  28. package/dist/types/index.js.map +1 -0
  29. package/dist/types/oauth.d.ts +35 -0
  30. package/dist/types/oauth.d.ts.map +1 -0
  31. package/dist/types/oauth.js +10 -0
  32. package/dist/types/oauth.js.map +1 -0
  33. package/dist/types/res/error.d.ts +11 -0
  34. package/dist/types/res/error.d.ts.map +1 -0
  35. package/dist/types/res/error.js +3 -0
  36. package/dist/types/res/error.js.map +1 -0
  37. package/dist/types/res/token.d.ts +38 -0
  38. package/dist/types/res/token.d.ts.map +1 -0
  39. package/dist/types/res/token.js +3 -0
  40. package/dist/types/res/token.js.map +1 -0
  41. package/dist/types/scopes.d.ts +6 -0
  42. package/dist/types/scopes.d.ts.map +1 -0
  43. package/dist/types/scopes.js +3 -0
  44. package/dist/types/scopes.js.map +1 -0
  45. package/dist/types/user.d.ts +76 -0
  46. package/dist/types/user.d.ts.map +1 -0
  47. package/dist/types/user.js +10 -0
  48. package/dist/types/user.js.map +1 -0
  49. package/dist/user.d.ts +13 -0
  50. package/dist/user.d.ts.map +1 -0
  51. package/dist/user.js +50 -0
  52. package/dist/user.js.map +1 -0
  53. package/package.json +32 -0
  54. package/readme.md +124 -0
package/dist/base.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { GoogleProviderConfig } from "@/types";
2
+ import OAuth2 from "./lib/oauth";
3
+ import User from "./lib/user";
4
+ declare class Google {
5
+ readonly oauth: OAuth2;
6
+ constructor(oauth: OAuth2);
7
+ static OAuth(config: GoogleProviderConfig): Google;
8
+ get user(): User;
9
+ set accessToken(token: string);
10
+ }
11
+ export default Google;
12
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,IAAI,MAAM,YAAY,CAAC;AAE9B,cAAM,MAAM;IACR,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;gBACX,KAAK,EAAE,MAAM;IAGzB,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,oBAAoB;IAGzC,IAAI,IAAI,SAKP;IAED,IAAI,WAAW,CAAC,KAAK,EAAE,MAAM,EAE5B;CACJ;AAED,eAAe,MAAM,CAAC"}
package/dist/base.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const oauth_1 = __importDefault(require("./lib/oauth"));
7
+ const user_1 = __importDefault(require("./lib/user"));
8
+ class Google {
9
+ constructor(oauth) {
10
+ this.oauth = oauth;
11
+ }
12
+ static OAuth(config) {
13
+ return new Google(new oauth_1.default(config));
14
+ }
15
+ get user() {
16
+ if (!this.oauth.accessToken) {
17
+ throw new Error("Access token is not set. Please authenticate first.");
18
+ }
19
+ return new user_1.default(this.oauth.accessToken);
20
+ }
21
+ set accessToken(token) {
22
+ this.oauth.accessToken = token;
23
+ }
24
+ }
25
+ exports.default = Google;
26
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":";;;;;AACA,wDAAiC;AACjC,sDAA8B;AAE9B,MAAM,MAAM;IAER,YAAY,KAAa;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IACD,MAAM,CAAC,KAAK,CAAC,MAA4B;QACrC,OAAO,IAAI,MAAM,CAAC,IAAI,eAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1C,CAAC;IACD,IAAI,IAAI;QACJ,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QAC3E,CAAC;QACD,OAAO,IAAI,cAAI,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC5C,CAAC;IAED,IAAI,WAAW,CAAC,KAAa;QACzB,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC;IACnC,CAAC;CACJ;AAED,kBAAe,MAAM,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { default as Google } from "./base";
2
+ export { default as OAuth2 } from "./lib/oauth";
3
+ export { default as User } from "./lib/user";
4
+ export type { GoogleProviderConfig, GoogleOAuthProvider } from "@/types";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,YAAY,CAAC;AAE7C,YAAY,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.User = exports.OAuth2 = exports.Google = void 0;
7
+ // src/lib/google/index.ts
8
+ var base_1 = require("./base");
9
+ Object.defineProperty(exports, "Google", { enumerable: true, get: function () { return __importDefault(base_1).default; } });
10
+ var oauth_1 = require("./lib/oauth");
11
+ Object.defineProperty(exports, "OAuth2", { enumerable: true, get: function () { return __importDefault(oauth_1).default; } });
12
+ var user_1 = require("./lib/user");
13
+ Object.defineProperty(exports, "User", { enumerable: true, get: function () { return __importDefault(user_1).default; } });
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,0BAA0B;AAC1B,+BAA2C;AAAlC,+GAAA,OAAO,OAAU;AAC1B,qCAAgD;AAAvC,gHAAA,OAAO,OAAU;AAC1B,mCAA6C;AAApC,6GAAA,OAAO,OAAQ"}
@@ -0,0 +1,22 @@
1
+ import { GoogleOAuthProvider, GoogleProviderConfig, Authorization } from "@/types";
2
+ declare class OAuth2 implements GoogleOAuthProvider {
3
+ readonly AUTH_BASE_URL = "https://accounts.google.com/o/oauth2/v2/auth";
4
+ readonly TOKEN_URL = "https://oauth2.googleapis.com/token";
5
+ readonly PROFILE_URL = "https://www.googleapis.com/oauth2/v3/userinfo";
6
+ readonly REVOCATION_URL = "https://oauth2.googleapis.com/revoke";
7
+ readonly clientId: Readonly<string>;
8
+ readonly clientSecret: Readonly<string>;
9
+ readonly authorization: Readonly<Authorization>;
10
+ accessToken: string | null;
11
+ constructor({ clientId, clientSecret, authorization }: GoogleProviderConfig);
12
+ url({ response_type, redirect_uri, access_type, prompt }: {
13
+ response_type?: string | undefined;
14
+ redirect_uri?: string | undefined;
15
+ access_type?: string | undefined;
16
+ prompt?: string | undefined;
17
+ }): string;
18
+ token(code: string, redirect_uri?: string): Promise<any>;
19
+ refresh(refresh_token: string): Promise<any>;
20
+ }
21
+ export default OAuth2;
22
+ //# sourceMappingURL=oauth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../src/lib/oauth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEnF,cAAM,MAAO,YAAW,mBAAmB;IACvC,QAAQ,CAAC,aAAa,kDAAmD;IACzE,QAAQ,CAAC,SAAS,yCAA8C;IAChE,QAAQ,CAAC,WAAW,mDAAsD;IAC1E,QAAQ,CAAC,cAAc,0CAA0C;IAEjE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACpC,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACxC,QAAQ,CAAC,aAAa,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;IAEhD,WAAW,EAAE,MAAM,GAAG,IAAI,CAAQ;gBAErB,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,EAAE,oBAAoB;IAc5E,GAAG,CAAC,EACA,aAAsB,EACtB,YAA6B,EAC7B,WAAyB,EACzB,MAAyB,EAC5B;;;;;KAAA;IAaK,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,GAAE,MAAsB;IAuBxD,OAAO,CAAC,aAAa,EAAE,MAAM;CAetC;AAED,eAAe,MAAM,CAAC"}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class OAuth2 {
4
+ constructor({ clientId, clientSecret, authorization }) {
5
+ this.AUTH_BASE_URL = "https://accounts.google.com/o/oauth2/v2/auth";
6
+ this.TOKEN_URL = "https://oauth2.googleapis.com/token";
7
+ this.PROFILE_URL = "https://www.googleapis.com/oauth2/v3/userinfo";
8
+ this.REVOCATION_URL = "https://oauth2.googleapis.com/revoke";
9
+ this.accessToken = null;
10
+ this.clientId = clientId;
11
+ this.clientSecret = clientSecret;
12
+ this.authorization = authorization || {
13
+ params: {
14
+ scope: [
15
+ "openid",
16
+ "email",
17
+ "profile",
18
+ ]
19
+ }
20
+ };
21
+ }
22
+ url({ response_type = "code", redirect_uri = "postmessage", access_type = "offline", prompt = "consent" }) {
23
+ const url = new URL(this.AUTH_BASE_URL);
24
+ url.searchParams.append("client_id", this.clientId);
25
+ url.searchParams.append("response_type", response_type);
26
+ url.searchParams.append("redirect_uri", redirect_uri);
27
+ url.searchParams.append("scope", this.authorization.params.scope.join(" "));
28
+ url.searchParams.append("access_type", access_type);
29
+ url.searchParams.append("prompt", prompt);
30
+ url.searchParams.append("state", Math.random().toString(36).substring(2, 15));
31
+ return url.toString();
32
+ }
33
+ async token(code, redirect_uri = "postmessage") {
34
+ const params = new URLSearchParams();
35
+ params.append("code", code);
36
+ params.append("client_id", this.clientId);
37
+ params.append("client_secret", this.clientSecret);
38
+ params.append("redirect_uri", redirect_uri);
39
+ params.append("grant_type", "authorization_code");
40
+ const response = await fetch(this.TOKEN_URL, {
41
+ method: "POST",
42
+ headers: {
43
+ "Content-Type": "application/x-www-form-urlencoded"
44
+ },
45
+ body: params.toString()
46
+ });
47
+ const data = await response.json();
48
+ if ('access_token' in data) {
49
+ this.accessToken = data.access_token;
50
+ }
51
+ return data;
52
+ }
53
+ async refresh(refresh_token) {
54
+ const params = new URLSearchParams();
55
+ params.append("refresh_token", refresh_token);
56
+ params.append("client_id", this.clientId);
57
+ params.append("client_secret", this.clientSecret);
58
+ params.append("grant_type", "refresh_token");
59
+ const response = await fetch(this.TOKEN_URL, {
60
+ method: "POST",
61
+ headers: {
62
+ "Content-Type": "application/x-www-form-urlencoded"
63
+ },
64
+ body: params.toString()
65
+ });
66
+ return await response.json();
67
+ }
68
+ }
69
+ exports.default = OAuth2;
70
+ //# sourceMappingURL=oauth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth.js","sourceRoot":"","sources":["../../src/lib/oauth.ts"],"names":[],"mappings":";;AAEA,MAAM,MAAM;IAYR,YAAa,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAwB;QAXnE,kBAAa,GAAI,8CAA8C,CAAC;QAChE,cAAS,GAAQ,qCAAqC,CAAC;QACvD,gBAAW,GAAM,+CAA+C,CAAC;QACjE,mBAAc,GAAG,sCAAsC,CAAC;QAMjE,gBAAW,GAAkB,IAAI,CAAC;QAG9B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,aAAa,GAAG,aAAa,IAAI;YAClC,MAAM,EAAE;gBACJ,KAAK,EAAE;oBACH,QAAQ;oBACR,OAAO;oBACP,SAAS;iBACZ;aACJ;SACJ,CAAA;IACL,CAAC;IAED,GAAG,CAAC,EACA,aAAa,GAAG,MAAM,EACtB,YAAY,GAAI,aAAa,EAC7B,WAAW,GAAK,SAAS,EACzB,MAAM,GAAU,SAAS,EAC5B;QACG,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACxC,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,WAAW,EAAM,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxD,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;QACxD,G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AAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,IAAI,cAAc,IAAI,IAAI,EAAE,CAAC;YACzB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC;QACzC,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,aAAqB;QAC/B,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;QACrC,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;QAC9C,MAAM,CAAC,MAAM,CAAC,WAAW,EAAM,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC9C,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAClD,MAAM,CAAC,MAAM,CAAC,YAAY,EAAK,eAAe,CAAC,CAAC;QAChD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE;YACzC,MAAM,EAAG,MAAM;YACf,OAAO,EAAE;gBACL,cAAc,EAAE,mCAAmC;aACtD;YACD,IAAI,EAAK,MAAM,CAAC,QAAQ,EAAE;SAC7B,CAAC,CAAC;QACH,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACjC,CAAC;CACJ;AAED,kBAAe,MAAM,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { GoogleUserProvider, GoogleUserProfile, GoogleDetailedUserProfile, GoogleTokenInfo, GoogleApiError } from "@/types";
2
+ declare class User implements GoogleUserProvider {
3
+ private readonly BASIC_PROFILE_URL;
4
+ private readonly DETAILED_PROFILE_URL;
5
+ private readonly TOKEN_INFO_URL;
6
+ private readonly accessToken;
7
+ constructor(accessToken: string);
8
+ profile(): Promise<GoogleUserProfile | GoogleApiError>;
9
+ detailedProfile(): Promise<GoogleDetailedUserProfile | GoogleApiError>;
10
+ verifyToken(): Promise<GoogleTokenInfo | GoogleApiError>;
11
+ }
12
+ export default User;
13
+ //# sourceMappingURL=user.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/lib/user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE5H,cAAM,IAAK,YAAW,kBAAkB;IACpC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA6C;IAC/E,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAgD;IACrF,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA6C;IAE5E,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;gBACzB,WAAW,EAAE,MAAM;IAIzB,OAAO,IAAI,OAAO,CAAC,iBAAiB,GAAG,cAAc,CAAC;IAiBtD,eAAe,IAAI,OAAO,CAAC,yBAAyB,GAAG,cAAc,CAAC;IAoBtE,WAAW,IAAI,OAAO,CAAC,eAAe,GAAG,cAAc,CAAC;CAajE;AAED,eAAe,IAAI,CAAC"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class User {
4
+ constructor(accessToken) {
5
+ this.BASIC_PROFILE_URL = "https://www.googleapis.com/oauth2/v2/me";
6
+ this.DETAILED_PROFILE_URL = "https://people.googleapis.com/v1/people/me";
7
+ this.TOKEN_INFO_URL = "https://oauth2.googleapis.com/tokeninfo";
8
+ this.accessToken = accessToken;
9
+ }
10
+ async profile() {
11
+ const response = await fetch(this.BASIC_PROFILE_URL, {
12
+ method: "GET",
13
+ headers: {
14
+ "Authorization": `Bearer ${this.accessToken}`
15
+ }
16
+ });
17
+ const data = await response.json();
18
+ if (!response.ok) {
19
+ return data;
20
+ }
21
+ return data;
22
+ }
23
+ async detailedProfile() {
24
+ const url = new URL(this.DETAILED_PROFILE_URL);
25
+ url.searchParams.set("personFields", "names,photos,emailAddresses,birthdays");
26
+ const response = await fetch(url.toString(), {
27
+ method: "GET",
28
+ headers: {
29
+ "Authorization": `Bearer ${this.accessToken}`
30
+ }
31
+ });
32
+ const data = await response.json();
33
+ if (!response.ok) {
34
+ return data;
35
+ }
36
+ return data;
37
+ }
38
+ async verifyToken() {
39
+ const url = new URL(this.TOKEN_INFO_URL);
40
+ url.searchParams.set("access_token", this.accessToken);
41
+ const response = await fetch(url.toString());
42
+ const data = await response.json();
43
+ if (!response.ok) {
44
+ return data;
45
+ }
46
+ return data;
47
+ }
48
+ }
49
+ exports.default = User;
50
+ //# sourceMappingURL=user.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/lib/user.ts"],"names":[],"mappings":";;AAEA,MAAM,IAAI;IAMN,YAAY,WAAmB;QALd,sBAAiB,GAAG,yCAAyC,CAAC;QAC9D,yBAAoB,GAAG,4CAA4C,CAAC;QACpE,mBAAc,GAAG,yCAAyC,CAAC;QAIxE,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,OAAO;QACT,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,iBAAiB,EAAE;YACjD,MAAM,EAAG,KAAK;YACd,OAAO,EAAE;gBACL,eAAe,EAAE,UAAU,IAAI,CAAC,WAAW,EAAE;aAChD;SACJ,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAEnC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACf,OAAO,IAAsB,CAAC;QAClC,CAAC;QAED,OAAO,IAAyB,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,eAAe;QACjB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAC/C,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,EAAE,uCAAuC,CAAC,CAAC;QAE9E,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE;YACzC,MAAM,EAAG,KAAK;YACd,OAAO,EAAE;gBACL,eAAe,EAAE,UAAU,IAAI,CAAC,WAAW,EAAE;aAChD;SACJ,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAEnC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACf,OAAO,IAAsB,CAAC;QAClC,CAAC;QAED,OAAO,IAAiC,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,WAAW;QACb,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QACzC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAEvD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC7C,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAEnC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACf,OAAO,IAAsB,CAAC;QAClC,CAAC;QAED,OAAO,IAAuB,CAAC;IACnC,CAAC;CACJ;AAED,kBAAe,IAAI,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { GoogleOAuthProvider, GoogleProviderConfig, Authorization } from "@/types";
2
+ declare class OAuth2 implements GoogleOAuthProvider {
3
+ readonly AUTH_BASE_URL = "https://accounts.google.com/o/oauth2/v2/auth";
4
+ readonly TOKEN_URL = "https://oauth2.googleapis.com/token";
5
+ readonly PROFILE_URL = "https://www.googleapis.com/oauth2/v3/userinfo";
6
+ readonly REVOCATION_URL = "https://oauth2.googleapis.com/revoke";
7
+ readonly clientId: Readonly<string>;
8
+ readonly clientSecret: Readonly<string>;
9
+ readonly authorization: Readonly<Authorization>;
10
+ accessToken: string | null;
11
+ constructor({ clientId, clientSecret, authorization }: GoogleProviderConfig);
12
+ url({ response_type, redirect_uri, access_type, prompt }: {
13
+ response_type?: string | undefined;
14
+ redirect_uri?: string | undefined;
15
+ access_type?: string | undefined;
16
+ prompt?: string | undefined;
17
+ }): string;
18
+ token(code: string, redirect_uri?: string): Promise<any>;
19
+ refresh(refresh_token: string): Promise<any>;
20
+ }
21
+ export default OAuth2;
22
+ //# sourceMappingURL=oauth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../src/oauth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEnF,cAAM,MAAO,YAAW,mBAAmB;IACvC,QAAQ,CAAC,aAAa,kDAAmD;IACzE,QAAQ,CAAC,SAAS,yCAA8C;IAChE,QAAQ,CAAC,WAAW,mDAAsD;IAC1E,QAAQ,CAAC,cAAc,0CAA0C;IAEjE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACpC,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACxC,QAAQ,CAAC,aAAa,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;IAEhD,WAAW,EAAE,MAAM,GAAG,IAAI,CAAQ;gBAErB,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,EAAE,oBAAoB;IAc5E,GAAG,CAAC,EACA,aAAsB,EACtB,YAA6B,EAC7B,WAAyB,EACzB,MAAyB,EAC5B;;;;;KAAA;IAaK,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,GAAE,MAAsB;IAuBxD,OAAO,CAAC,aAAa,EAAE,MAAM;CAetC;AAED,eAAe,MAAM,CAAC"}
package/dist/oauth.js ADDED
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class OAuth2 {
4
+ constructor({ clientId, clientSecret, authorization }) {
5
+ this.AUTH_BASE_URL = "https://accounts.google.com/o/oauth2/v2/auth";
6
+ this.TOKEN_URL = "https://oauth2.googleapis.com/token";
7
+ this.PROFILE_URL = "https://www.googleapis.com/oauth2/v3/userinfo";
8
+ this.REVOCATION_URL = "https://oauth2.googleapis.com/revoke";
9
+ this.accessToken = null;
10
+ this.clientId = clientId;
11
+ this.clientSecret = clientSecret;
12
+ this.authorization = authorization || {
13
+ params: {
14
+ scope: [
15
+ "openid",
16
+ "email",
17
+ "profile",
18
+ ]
19
+ }
20
+ };
21
+ }
22
+ url({ response_type = "code", redirect_uri = "postmessage", access_type = "offline", prompt = "consent" }) {
23
+ const url = new URL(this.AUTH_BASE_URL);
24
+ url.searchParams.append("client_id", this.clientId);
25
+ url.searchParams.append("response_type", response_type);
26
+ url.searchParams.append("redirect_uri", redirect_uri);
27
+ url.searchParams.append("scope", this.authorization.params.scope.join(" "));
28
+ url.searchParams.append("access_type", access_type);
29
+ url.searchParams.append("prompt", prompt);
30
+ url.searchParams.append("state", Math.random().toString(36).substring(2, 15));
31
+ return url.toString();
32
+ }
33
+ async token(code, redirect_uri = "postmessage") {
34
+ const params = new URLSearchParams();
35
+ params.append("code", code);
36
+ params.append("client_id", this.clientId);
37
+ params.append("client_secret", this.clientSecret);
38
+ params.append("redirect_uri", redirect_uri);
39
+ params.append("grant_type", "authorization_code");
40
+ const response = await fetch(this.TOKEN_URL, {
41
+ method: "POST",
42
+ headers: {
43
+ "Content-Type": "application/x-www-form-urlencoded"
44
+ },
45
+ body: params.toString()
46
+ });
47
+ const data = await response.json();
48
+ if ('access_token' in data) {
49
+ this.accessToken = data.access_token;
50
+ }
51
+ return data;
52
+ }
53
+ async refresh(refresh_token) {
54
+ const params = new URLSearchParams();
55
+ params.append("refresh_token", refresh_token);
56
+ params.append("client_id", this.clientId);
57
+ params.append("client_secret", this.clientSecret);
58
+ params.append("grant_type", "refresh_token");
59
+ const response = await fetch(this.TOKEN_URL, {
60
+ method: "POST",
61
+ headers: {
62
+ "Content-Type": "application/x-www-form-urlencoded"
63
+ },
64
+ body: params.toString()
65
+ });
66
+ return await response.json();
67
+ }
68
+ }
69
+ exports.default = OAuth2;
70
+ //# sourceMappingURL=oauth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth.js","sourceRoot":"","sources":["../src/oauth.ts"],"names":[],"mappings":";;AAEA,MAAM,MAAM;IAYR,YAAa,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAwB;QAXnE,kBAAa,GAAI,8CAA8C,CAAC;QAChE,cAAS,GAAQ,qCAAqC,CAAC;QACvD,gBAAW,GAAM,+CAA+C,CAAC;QACjE,mBAAc,GAAG,sCAAsC,CAAC;QAMjE,gBAAW,GAAkB,IAAI,CAAC;QAG9B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,aAAa,GAAG,aAAa,IAAI;YAClC,MAAM,EAAE;gBACJ,KAAK,EAAE;oBACH,QAAQ;oBACR,OAAO;oBACP,SAAS;iBACZ;aACJ;SACJ,CAAA;IACL,CAAC;IAED,GAAG,CAAC,EACA,aAAa,GAAG,MAAM,EACtB,YAAY,GAAI,aAAa,EAC7B,WAAW,GAAK,SAAS,EACzB,MAAM,GAAU,SAAS,EAC5B;QACG,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACxC,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,WAAW,EAAM,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxD,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;QACxD,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,cAAc,EAAG,YAAY,CAAC,CAAC;QACvD,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,EAAU,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,IAA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B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,aAAqB;QAC/B,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;QACrC,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;QAC9C,MAAM,CAAC,MAAM,CAAC,WAAW,EAAM,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC9C,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAClD,MAAM,CAAC,MAAM,CAAC,YAAY,EAAK,eAAe,CAAC,CAAC;QAChD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE;YACzC,MAAM,EAAG,MAAM;YACf,OAAO,EAAE;gBACL,cAAc,EAAE,mCAAmC;aACtD;YACD,IAAI,EAAK,MAAM,CAAC,QAAQ,EAAE;SAC7B,CAAC,CAAC;QACH,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACjC,CAAC;CACJ;AAED,kBAAe,MAAM,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { GoogleScope } from "./scopes";
2
+ /**
3
+ * Google OAuth 設定
4
+ */
5
+ export type GoogleProviderConfig = {
6
+ /** Google OAuth Client ID */
7
+ clientId: string;
8
+ /** Google OAuth Client Secret */
9
+ clientSecret: string;
10
+ /** OAuth 認可パラメータ */
11
+ authorization?: Authorization;
12
+ };
13
+ /**
14
+ * OAuth 認可設定
15
+ */
16
+ export type Authorization = {
17
+ params: {
18
+ /** リクエストするスコープ */
19
+ scope: GoogleScope[];
20
+ };
21
+ };
22
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IAC/B,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,iCAAiC;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB;IACpB,aAAa,CAAC,EAAE,aAAa,CAAC;CACjC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IACxB,MAAM,EAAE;QACJ,kBAAkB;QAClB,KAAK,EAAE,WAAW,EAAE,CAAC;KACxB,CAAC;CACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Google OAuth ライブラリの型定義
3
+ * @packageDocumentation
4
+ */
5
+ export type { GoogleProviderConfig, Authorization } from "./config";
6
+ export type { GoogleOAuthProvider, LoginURL, } from "./oauth";
7
+ export type { GoogleOAuthTokenResponse, GoogleOAuthTokenAuthorizationCodeResponse, GoogleOAuthTokenRefreshResponse, GoogleOAuthTokenErrorResponse } from "./res/token";
8
+ export type { GoogleUserProvider, GoogleUserProfile, GoogleDetailedUserProfile, GoogleTokenInfo } from "./user";
9
+ export type { GoogleScope } from "./scopes";
10
+ export type { GoogleApiError } from "./res/error";
11
+ export { isOAuthError } from "./oauth";
12
+ export { isUserApiError } from "./user";
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,YAAY,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGpE,YAAY,EACR,mBAAmB,EACnB,QAAQ,GACX,MAAM,SAAS,CAAC;AACjB,YAAY,EACR,wBAAwB,EACxB,yCAAyC,EACzC,+BAA+B,EAC/B,6BAA6B,EAChC,MAAM,aAAa,CAAC;AAGrB,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAGhH,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAG5C,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /**
3
+ * Google OAuth ライブラリの型定義
4
+ * @packageDocumentation
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.isUserApiError = exports.isOAuthError = void 0;
8
+ // ユーティリティ関数
9
+ var oauth_1 = require("./oauth");
10
+ Object.defineProperty(exports, "isOAuthError", { enumerable: true, get: function () { return oauth_1.isOAuthError; } });
11
+ var user_1 = require("./user");
12
+ Object.defineProperty(exports, "isUserApiError", { enumerable: true, get: function () { return user_1.isUserApiError; } });
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA0BH,YAAY;AACZ,iCAAuC;AAA9B,qGAAA,YAAY,OAAA;AACrB,+BAAwC;AAA/B,sGAAA,cAAc,OAAA"}
@@ -0,0 +1,35 @@
1
+ import type { GoogleOAuthTokenResponse, GoogleOAuthTokenRefreshResponse, GoogleOAuthTokenErrorResponse } from "./res/token";
2
+ /**
3
+ * OAuth 認可URL生成パラメータ
4
+ */
5
+ export type LoginURL = {
6
+ response_type?: "code" | "token";
7
+ redirect_uri?: string;
8
+ access_type?: "online" | "offline";
9
+ prompt?: "none" | "consent" | "select_account";
10
+ };
11
+ /**
12
+ * Google OAuth プロバイダーインターフェース
13
+ */
14
+ export type GoogleOAuthProvider = {
15
+ readonly clientId: string;
16
+ readonly clientSecret: string;
17
+ readonly authorization: Readonly<import("./config").Authorization>;
18
+ /**
19
+ * OAuth 認可URLを生成
20
+ */
21
+ url(params: LoginURL): string;
22
+ /**
23
+ * 認可コードをトークンと交換
24
+ */
25
+ token(code: string, redirect_uri?: string): Promise<GoogleOAuthTokenResponse>;
26
+ /**
27
+ * リフレッシュトークンで新しいアクセストークンを取得
28
+ */
29
+ refresh(refresh_token: string): Promise<GoogleOAuthTokenRefreshResponse>;
30
+ };
31
+ /**
32
+ * OAuthレスポンスがエラーかどうかを判定
33
+ */
34
+ export declare function isOAuthError(response: GoogleOAuthTokenResponse): response is GoogleOAuthTokenErrorResponse;
35
+ //# sourceMappingURL=oauth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../src/types/oauth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,wBAAwB,EACxB,+BAA+B,EAC/B,6BAA6B,EAChC,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IACnB,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,gBAAgB,CAAC;CAClD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,QAAQ,CAAC,OAAO,UAAU,EAAE,aAAa,CAAC,CAAC;IAEnE;;OAEG;IACH,GAAG,CAAC,MAAM,EAAE,QAAQ,GAAG,MAAM,CAAC;IAE9B;;OAEG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAE9E;;OAEG;IACH,OAAO,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,+BAA+B,CAAC,CAAC;CAC5E,CAAC;AAEF;;GAEG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,wBAAwB,GAAG,QAAQ,IAAI,6BAA6B,CAE1G"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isOAuthError = isOAuthError;
4
+ /**
5
+ * OAuthレスポンスがエラーかどうかを判定
6
+ */
7
+ function isOAuthError(response) {
8
+ return 'error' in response;
9
+ }
10
+ //# sourceMappingURL=oauth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth.js","sourceRoot":"","sources":["../../src/types/oauth.ts"],"names":[],"mappings":";;AA2CA,oCAEC;AALD;;GAEG;AACH,SAAgB,YAAY,CAAC,QAAkC;IAC3D,OAAO,OAAO,IAAI,QAAQ,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Google API エラーレスポンス
3
+ */
4
+ export type GoogleApiError = {
5
+ error: {
6
+ code: number;
7
+ message: string;
8
+ status: string;
9
+ };
10
+ };
11
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../src/types/res/error.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IACzB,KAAK,EAAE;QACH,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;KAClB,CAAC;CACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/types/res/error.ts"],"names":[],"mappings":""}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Google OAuth トークンレスポンスの共通フィールド
3
+ */
4
+ export interface GoogleOAuthTokenBase {
5
+ access_token: string;
6
+ expires_in: number;
7
+ scope?: string;
8
+ token_type: "Bearer";
9
+ }
10
+ /**
11
+ * 認可コード (authorization_code) 交換成功時のレスポンス
12
+ * 初回 or consent 時のみ refresh_token / id_token が含まれる
13
+ */
14
+ export interface GoogleOAuthTokenAuthorizationCodeResponse extends GoogleOAuthTokenBase {
15
+ grant_type: "authorization_code";
16
+ refresh_token?: string;
17
+ id_token?: string;
18
+ }
19
+ /**
20
+ * refresh_token 使用時のレスポンス
21
+ * 注意: refresh_token / id_token は含まれない
22
+ */
23
+ export interface GoogleOAuthTokenRefreshResponse extends GoogleOAuthTokenBase {
24
+ grant_type: "refresh_token";
25
+ }
26
+ /**
27
+ * Google OAuth エラーレスポンス
28
+ */
29
+ export interface GoogleOAuthTokenErrorResponse {
30
+ error: "invalid_request" | "invalid_client" | "invalid_grant" | "unauthorized_client" | "unsupported_grant_type" | string;
31
+ error_description?: string;
32
+ error_uri?: string;
33
+ }
34
+ /**
35
+ * Google OAuth トークンレスポンス(完全版 Union)
36
+ */
37
+ export type GoogleOAuthTokenResponse = GoogleOAuthTokenAuthorizationCodeResponse | GoogleOAuthTokenRefreshResponse | GoogleOAuthTokenErrorResponse;
38
+ //# sourceMappingURL=token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../../src/types/res/token.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,QAAQ,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,yCACf,SAAQ,oBAAoB;IAC5B,UAAU,EAAE,oBAAoB,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,+BACf,SAAQ,oBAAoB;IAC5B,UAAU,EAAE,eAAe,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C,KAAK,EACD,iBAAiB,GACjB,gBAAgB,GAChB,eAAe,GACf,qBAAqB,GACrB,wBAAwB,GACxB,MAAM,CAAC;IACX,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAChC,yCAAyC,GACzC,+BAA+B,GAC/B,6BAA6B,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.js","sourceRoot":"","sources":["../../../src/types/res/token.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Google API スコープの型定義
3
+ * @see https://developers.google.com/identity/protocols/oauth2/scopes
4
+ */
5
+ export type GoogleScope = "openid" | "email" | "profile" | "https://www.googleapis.com/auth/gmail.readonly" | "https://www.googleapis.com/auth/gmail.modify" | "https://www.googleapis.com/auth/gmail.compose" | "https://www.googleapis.com/auth/gmail.send" | "https://www.googleapis.com/auth/gmail.insert" | "https://www.googleapis.com/auth/gmail.labels" | "https://www.googleapis.com/auth/gmail.metadata" | "https://www.googleapis.com/auth/gmail.settings.basic" | "https://www.googleapis.com/auth/gmail.settings.sharing" | "https://www.googleapis.com/auth/gmail.addons.current.action.compose" | "https://www.googleapis.com/auth/gmail.addons.current.message.action" | "https://www.googleapis.com/auth/gmail.addons.current.message.metadata" | "https://www.googleapis.com/auth/gmail.addons.current.message.readonly" | "https://www.googleapis.com/auth/drive" | "https://www.googleapis.com/auth/drive.file" | "https://www.googleapis.com/auth/drive.readonly" | "https://www.googleapis.com/auth/drive.metadata.readonly" | "https://www.googleapis.com/auth/drive.appdata" | "https://www.googleapis.com/auth/drive.photos.readonly" | "https://www.googleapis.com/auth/calendar" | "https://www.googleapis.com/auth/calendar.events" | "https://www.googleapis.com/auth/calendar.readonly" | "https://www.googleapis.com/auth/contacts" | "https://www.googleapis.com/auth/contacts.readonly" | "https://www.googleapis.com/auth/userinfo.email" | "https://www.googleapis.com/auth/userinfo.profile" | "https://www.googleapis.com/auth/admin.directory.user" | "https://www.googleapis.com/auth/admin.directory.group" | "https://www.googleapis.com/auth/cloud-platform";
6
+ //# sourceMappingURL=scopes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scopes.d.ts","sourceRoot":"","sources":["../../src/types/scopes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,WAAW,GAEjB,QAAQ,GACR,OAAO,GACP,SAAS,GAET,gDAAgD,GAChD,8CAA8C,GAC9C,+CAA+C,GAC/C,4CAA4C,GAC5C,8CAA8C,GAC9C,8CAA8C,GAC9C,gDAAgD,GAChD,sDAAsD,GACtD,wDAAwD,GACxD,qEAAqE,GACrE,qEAAqE,GACrE,uEAAuE,GACvE,uEAAuE,GAEvE,uCAAuC,GACvC,4CAA4C,GAC5C,gDAAgD,GAChD,yDAAyD,GACzD,+CAA+C,GAC/C,uDAAuD,GAEvD,0CAA0C,GAC1C,iDAAiD,GACjD,mDAAmD,GAEnD,0CAA0C,GAC1C,mDAAmD,GAEnD,gDAAgD,GAChD,kDAAkD,GAElD,sDAAsD,GACtD,uDAAuD,GAEvD,gDAAgD,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=scopes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scopes.js","sourceRoot":"","sources":["../../src/types/scopes.ts"],"names":[],"mappings":""}
@@ -0,0 +1,76 @@
1
+ import type { GoogleApiError } from "./res/error";
2
+ /**
3
+ * Google 基本ユーザー情報
4
+ */
5
+ export type GoogleUserProfile = {
6
+ id: string;
7
+ email: string;
8
+ verified_email: boolean;
9
+ name: string;
10
+ given_name: string;
11
+ family_name: string;
12
+ picture: string;
13
+ locale: string;
14
+ };
15
+ /**
16
+ * Google ユーザー情報プロバイダーインターフェース
17
+ */
18
+ export type GoogleUserProvider = {
19
+ /**
20
+ * アクセストークンを使用して基本的なユーザー情報を取得
21
+ */
22
+ profile(accessToken: string): Promise<GoogleUserProfile | GoogleApiError>;
23
+ /**
24
+ * People API を使用して詳細なユーザー情報を取得
25
+ */
26
+ detailedProfile(accessToken: string): Promise<GoogleDetailedUserProfile | GoogleApiError>;
27
+ /**
28
+ * アクセストークンの有効性を検証
29
+ */
30
+ verifyToken(accessToken: string): Promise<GoogleTokenInfo | GoogleApiError>;
31
+ };
32
+ /**
33
+ * Google 詳細ユーザー情報 (People API)
34
+ */
35
+ export type GoogleDetailedUserProfile = {
36
+ resourceName?: string;
37
+ names?: Array<{
38
+ displayName?: string;
39
+ givenName?: string;
40
+ familyName?: string;
41
+ }>;
42
+ photos?: Array<{
43
+ url?: string;
44
+ }>;
45
+ emailAddresses?: Array<{
46
+ value?: string;
47
+ type?: string;
48
+ verified?: boolean;
49
+ }>;
50
+ birthdays?: Array<{
51
+ date?: {
52
+ year?: number;
53
+ month?: number;
54
+ day?: number;
55
+ };
56
+ }>;
57
+ };
58
+ /**
59
+ * Google トークン情報
60
+ */
61
+ export type GoogleTokenInfo = {
62
+ azp?: string;
63
+ aud?: string;
64
+ sub?: string;
65
+ scope?: string;
66
+ exp?: string;
67
+ expires_in?: string;
68
+ email?: string;
69
+ email_verified?: string;
70
+ access_type?: string;
71
+ };
72
+ /**
73
+ * ユーザー情報レスポンスがエラーかどうかを判定
74
+ */
75
+ export declare function isUserApiError(response: GoogleUserProfile | GoogleApiError): response is GoogleApiError;
76
+ //# sourceMappingURL=user.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.d.ts","source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;IACH,SAAS,CAAC,EAAE,KAAK,CAAC;QACd,IAAI,CAAC,EAAE;YACH,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,KAAK,CAAC,EAAE,MAAM,CAAC;YACf,GAAG,CAAC,EAAE,MAAM,CAAC;SAChB,CAAC;KACL,CAAC,CAAC;CACN,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAIF;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,iBAAiB,GAAG,cAAc,GAAG,QAAQ,IAAI,cAAc,CAEvG"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isUserApiError = isUserApiError;
4
+ /**
5
+ * ユーザー情報レスポンスがエラーかどうかを判定
6
+ */
7
+ function isUserApiError(response) {
8
+ return 'error' in response;
9
+ }
10
+ //# sourceMappingURL=user.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/types/user.ts"],"names":[],"mappings":";;AAmFA,wCAEC;AALD;;GAEG;AACH,SAAgB,cAAc,CAAC,QAA4C;IACvE,OAAO,OAAO,IAAI,QAAQ,CAAC;AAC/B,CAAC"}
package/dist/user.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { GoogleUserProvider, GoogleUserProfile, GoogleDetailedUserProfile, GoogleTokenInfo, GoogleApiError } from "@/types";
2
+ declare class User implements GoogleUserProvider {
3
+ private readonly BASIC_PROFILE_URL;
4
+ private readonly DETAILED_PROFILE_URL;
5
+ private readonly TOKEN_INFO_URL;
6
+ private readonly accessToken;
7
+ constructor(accessToken: string);
8
+ profile(): Promise<GoogleUserProfile | GoogleApiError>;
9
+ detailedProfile(): Promise<GoogleDetailedUserProfile | GoogleApiError>;
10
+ verifyToken(): Promise<GoogleTokenInfo | GoogleApiError>;
11
+ }
12
+ export default User;
13
+ //# sourceMappingURL=user.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../src/user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE5H,cAAM,IAAK,YAAW,kBAAkB;IACpC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA6C;IAC/E,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAgD;IACrF,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA6C;IAE5E,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;gBACzB,WAAW,EAAE,MAAM;IAIzB,OAAO,IAAI,OAAO,CAAC,iBAAiB,GAAG,cAAc,CAAC;IAiBtD,eAAe,IAAI,OAAO,CAAC,yBAAyB,GAAG,cAAc,CAAC;IAoBtE,WAAW,IAAI,OAAO,CAAC,eAAe,GAAG,cAAc,CAAC;CAajE;AAED,eAAe,IAAI,CAAC"}
package/dist/user.js ADDED
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class User {
4
+ constructor(accessToken) {
5
+ this.BASIC_PROFILE_URL = "https://www.googleapis.com/oauth2/v2/me";
6
+ this.DETAILED_PROFILE_URL = "https://people.googleapis.com/v1/people/me";
7
+ this.TOKEN_INFO_URL = "https://oauth2.googleapis.com/tokeninfo";
8
+ this.accessToken = accessToken;
9
+ }
10
+ async profile() {
11
+ const response = await fetch(this.BASIC_PROFILE_URL, {
12
+ method: "GET",
13
+ headers: {
14
+ "Authorization": `Bearer ${this.accessToken}`
15
+ }
16
+ });
17
+ const data = await response.json();
18
+ if (!response.ok) {
19
+ return data;
20
+ }
21
+ return data;
22
+ }
23
+ async detailedProfile() {
24
+ const url = new URL(this.DETAILED_PROFILE_URL);
25
+ url.searchParams.set("personFields", "names,photos,emailAddresses,birthdays");
26
+ const response = await fetch(url.toString(), {
27
+ method: "GET",
28
+ headers: {
29
+ "Authorization": `Bearer ${this.accessToken}`
30
+ }
31
+ });
32
+ const data = await response.json();
33
+ if (!response.ok) {
34
+ return data;
35
+ }
36
+ return data;
37
+ }
38
+ async verifyToken() {
39
+ const url = new URL(this.TOKEN_INFO_URL);
40
+ url.searchParams.set("access_token", this.accessToken);
41
+ const response = await fetch(url.toString());
42
+ const data = await response.json();
43
+ if (!response.ok) {
44
+ return data;
45
+ }
46
+ return data;
47
+ }
48
+ }
49
+ exports.default = User;
50
+ //# sourceMappingURL=user.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.js","sourceRoot":"","sources":["../src/user.ts"],"names":[],"mappings":";;AAEA,MAAM,IAAI;IAMN,YAAY,WAAmB;QALd,sBAAiB,GAAG,yCAAyC,CAAC;QAC9D,yBAAoB,GAAG,4CAA4C,CAAC;QACpE,mBAAc,GAAG,yCAAyC,CAAC;QAIxE,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,OAAO;QACT,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,iBAAiB,EAAE;YACjD,MAAM,EAAG,KAAK;YACd,OAAO,EAAE;gBACL,eAAe,EAAE,UAAU,IAAI,CAAC,WAAW,EAAE;aAChD;SACJ,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAEnC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACf,O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 "oss",
8
+ "oauth",
9
+ "google",
10
+ "provider",
11
+ "sso"
12
+ ],
13
+ "license": "ISC",
14
+ "author": "tanahiro2010",
15
+ "main": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsc",
22
+ "docs": "typedoc",
23
+ "test": "echo \"Error: no test specified\" && exit 1"
24
+ },
25
+ "devDependencies": {
26
+ "typedoc": "^0.28.15",
27
+ "typescript": "^5.9.3"
28
+ },
29
+ "repository": {
30
+ "url": "https://github.com/tanahiro2010/Google_OAuth_Lib"
31
+ }
32
+ }
package/readme.md ADDED
@@ -0,0 +1,124 @@
1
+ # GoogleOAuthLib
2
+
3
+ [![npm version](https://badge.fury.io/js/google-oauth-lib.svg)](https://badge.fury.io/js/google-oauth-lib)
4
+ [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](https://opensource.org/licenses/ISC)
5
+
6
+ Node.js向けのGoogle OAuth 2.0認証ライブラリ。TypeScriptで書かれ、完全な型定義を提供します。
7
+
8
+ ## 特徴
9
+
10
+ - **OAuth 2.0完全対応**: Google OAuthの全機能をサポート(予定)
11
+ - **TypeScript対応**: 完全な型定義付きで開発効率向上
12
+ - **シンプルなAPI**: 直感的なインターフェース
13
+ - **拡張性**: Google APIsへの対応も計画中
14
+ - **OSS**: オープンソースでコミュニティ貢献歓迎
15
+
16
+ ## インストール
17
+
18
+ ```bash
19
+ npm install google_oauth_provider
20
+ ```
21
+
22
+ ## クイックスタート
23
+
24
+ ```typescript
25
+ import { Google, OAuth2, User } from 'google_oauth_provider';
26
+
27
+ // 設定
28
+ const config = {
29
+ clientId: 'your-client-id',
30
+ clientSecret: 'your-client-secret',
31
+ redirectUri: 'http://localhost:3000/callback'
32
+ };
33
+
34
+ // OAuthインスタンス作成
35
+ const oauth = new OAuth2(config);
36
+
37
+ // 認証URL生成
38
+ const authUrl = oauth.getAuthorizationUrl({
39
+ scope: ['https://www.googleapis.com/auth/userinfo.profile']
40
+ });
41
+
42
+ // トークン取得(コールバック後)
43
+ const tokens = await oauth.exchangeCodeForTokens(code);
44
+
45
+ // ユーザー情報取得
46
+ const userProvider = new User();
47
+ const profile = await userProvider.profile(tokens.access_token);
48
+ ```
49
+
50
+ ## API リファレンス
51
+
52
+ ### OAuth2
53
+
54
+ Google OAuth 2.0認証を扱うクラス。
55
+
56
+ - `getAuthorizationUrl(options)`: 認証URLを生成
57
+ - `exchangeCodeForTokens(code)`: 認可コードをトークンと交換
58
+ - `refreshAccessToken(refreshToken)`: アクセストークンをリフレッシュ
59
+
60
+ ### User
61
+
62
+ Googleユーザー情報を取得するクラス。
63
+
64
+ - `profile(accessToken)`: 基本ユーザー情報を取得
65
+ - `detailedProfile(accessToken)`: People APIで詳細情報を取得
66
+ - `verifyToken(accessToken)`: トークンの有効性を検証
67
+
68
+ ### Google (メインクラス)
69
+
70
+ OAuthとUserを統合したメインクラス。
71
+
72
+ ```typescript
73
+ const google = Google.OAuth(config);
74
+ ```
75
+
76
+ ## 設定
77
+
78
+ ```typescript
79
+ interface GoogleProviderConfig {
80
+ clientId: string;
81
+ clientSecret: string;
82
+ redirectUri: string;
83
+ }
84
+ ```
85
+
86
+ ## 開発
87
+
88
+ ### ビルド
89
+
90
+ ```bash
91
+ npm run build
92
+ ```
93
+
94
+ ### テスト
95
+
96
+ ```bash
97
+ npm test
98
+ ```
99
+
100
+ ## ロードマップ
101
+
102
+ - [x] OAuth 2.0基本認証
103
+ - [ ] OAuth 2.0完全対応(全スコープ、PKCEなど)
104
+ - [ ] Google APIs統合(Drive, Gmail, Calendarなど)
105
+ - [ ] ドキュメント充実
106
+ - [ ] テスト追加
107
+
108
+ ## 貢献
109
+
110
+ このプロジェクトはOSSです。IssueやPull Requestを歓迎します!
111
+
112
+ 1. Fork
113
+ 2. Feature branch作成 (`git checkout -b feature/AmazingFeature`)
114
+ 3. コミット (`git commit -m 'Add some AmazingFeature'`)
115
+ 4. Push (`git push origin feature/AmazingFeature`)
116
+ 5. Pull Request
117
+
118
+ ## ライセンス
119
+
120
+ ISC License
121
+
122
+ ## 作者
123
+
124
+ [tanahiro2010](https://github.com/tanahiro2010)