google-oauth-lib 1.0.0 → 1.0.1

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 (2) hide show
  1. package/package.json +1 -1
  2. package/readme.md +35 -23
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "google-oauth-lib",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Google OAuth Provider for Node.js",
5
5
  "keywords": [
6
6
  "tanahiro2010",
package/readme.md CHANGED
@@ -3,7 +3,8 @@
3
3
  [![npm version](https://badge.fury.io/js/google-oauth-lib.svg)](https://badge.fury.io/js/google-oauth-lib)
4
4
  [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](https://opensource.org/licenses/ISC)
5
5
 
6
- Node.js向けのGoogle OAuth 2.0認証ライブラリ。TypeScriptで書かれ、完全な型定義を提供します。
6
+ Node.js向けのGoogle OAuth
7
+ 2.0認証ライブラリ。TypeScriptで書かれ、完全な型定義を提供します。
7
8
 
8
9
  ## 特徴
9
10
 
@@ -16,35 +17,46 @@ Node.js向けのGoogle OAuth 2.0認証ライブラリ。TypeScriptで書かれ
16
17
  ## インストール
17
18
 
18
19
  ```bash
19
- npm install google_oauth_provider
20
+ npm install google-oauth-lib
20
21
  ```
21
22
 
22
23
  ## クイックスタート
23
24
 
24
25
  ```typescript
25
- import { Google, OAuth2, User } from 'google_oauth_provider';
26
+ import { Google } from "google-oauth-lib";
26
27
 
27
28
  // 設定
28
29
  const config = {
29
- clientId: 'your-client-id',
30
- clientSecret: 'your-client-secret',
31
- redirectUri: 'http://localhost:3000/callback'
30
+ clientId: "your-client-id",
31
+ clientSecret: "your-client-secret",
32
+ redirectUri: "http://localhost:3000/callback",
32
33
  };
33
34
 
34
- // OAuthインスタンス作成
35
- const oauth = new OAuth2(config);
35
+ // Googleクライアント作成
36
+ const google = Google.OAuth(const GoogleClient = Google.OAuth({
37
+ clientId: process.env.GOOGLE_CLIENT_ID || "",
38
+ clientSecret: process.env.GOOGLE_CLIENT_SECRET || "",
39
+ authorization: {
40
+ params: {
41
+ scope: [
42
+ "openid",
43
+ "email",
44
+ "profile"
45
+ ]
46
+ }
47
+ }
48
+ }););
36
49
 
37
50
  // 認証URL生成
38
- const authUrl = oauth.getAuthorizationUrl({
39
- scope: ['https://www.googleapis.com/auth/userinfo.profile']
51
+ const authUrl = google.oauth.url({
52
+ redirect_uri: "http://localhost:3000"
40
53
  });
41
54
 
42
55
  // トークン取得(コールバック後)
43
- const tokens = await oauth.exchangeCodeForTokens(code);
56
+ const tokens = await google.oauth.token(code);
44
57
 
45
58
  // ユーザー情報取得
46
- const userProvider = new User();
47
- const profile = await userProvider.profile(tokens.access_token);
59
+ const profile = await google.user.profile();
48
60
  ```
49
61
 
50
62
  ## API リファレンス
@@ -53,17 +65,17 @@ const profile = await userProvider.profile(tokens.access_token);
53
65
 
54
66
  Google OAuth 2.0認証を扱うクラス。
55
67
 
56
- - `getAuthorizationUrl(options)`: 認証URLを生成
57
- - `exchangeCodeForTokens(code)`: 認可コードをトークンと交換
58
- - `refreshAccessToken(refreshToken)`: アクセストークンをリフレッシュ
68
+ - `url(options)`: 認証URLを生成
69
+ - `token(code)`: 認可コードをトークンと交換
70
+ - `refresh(refreshToken)`: アクセストークンをリフレッシュ
59
71
 
60
72
  ### User
61
73
 
62
74
  Googleユーザー情報を取得するクラス。
63
75
 
64
- - `profile(accessToken)`: 基本ユーザー情報を取得
65
- - `detailedProfile(accessToken)`: People APIで詳細情報を取得
66
- - `verifyToken(accessToken)`: トークンの有効性を検証
76
+ - `profile()`: 基本ユーザー情報を取得
77
+ - `detailedProfile()`: People APIで詳細情報を取得
78
+ - `verifyToken()`: トークンの有効性を検証
67
79
 
68
80
  ### Google (メインクラス)
69
81
 
@@ -77,9 +89,9 @@ const google = Google.OAuth(config);
77
89
 
78
90
  ```typescript
79
91
  interface GoogleProviderConfig {
80
- clientId: string;
81
- clientSecret: string;
82
- redirectUri: string;
92
+ clientId: string;
93
+ clientSecret: string;
94
+ redirectUri: string;
83
95
  }
84
96
  ```
85
97
 
@@ -121,4 +133,4 @@ ISC License
121
133
 
122
134
  ## 作者
123
135
 
124
- [tanahiro2010](https://github.com/tanahiro2010)
136
+ [tanahiro2010](https://github.com/tanahiro2010)