google-oauth-lib 1.0.0 → 1.0.2
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/package.json +1 -1
- package/readme.md +36 -24
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# google-oauth-lib
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/js/google-oauth-lib)
|
|
4
4
|
[](https://opensource.org/licenses/ISC)
|
|
5
5
|
|
|
6
|
-
Node.js向けのGoogle OAuth
|
|
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
|
|
20
|
+
npm install google-oauth-lib
|
|
20
21
|
```
|
|
21
22
|
|
|
22
23
|
## クイックスタート
|
|
23
24
|
|
|
24
25
|
```typescript
|
|
25
|
-
import { Google
|
|
26
|
+
import { Google } from "google-oauth-lib";
|
|
26
27
|
|
|
27
28
|
// 設定
|
|
28
29
|
const config = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
clientId: "your-client-id",
|
|
31
|
+
clientSecret: "your-client-secret",
|
|
32
|
+
redirectUri: "http://localhost:3000/callback",
|
|
32
33
|
};
|
|
33
34
|
|
|
34
|
-
//
|
|
35
|
-
const
|
|
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.
|
|
39
|
-
|
|
51
|
+
const authUrl = google.oauth.url({
|
|
52
|
+
redirect_uri: "http://localhost:3000"
|
|
40
53
|
});
|
|
41
54
|
|
|
42
55
|
// トークン取得(コールバック後)
|
|
43
|
-
const tokens = await oauth.
|
|
56
|
+
const tokens = await google.oauth.token(code);
|
|
44
57
|
|
|
45
58
|
// ユーザー情報取得
|
|
46
|
-
const
|
|
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
|
-
- `
|
|
57
|
-
- `
|
|
58
|
-
- `
|
|
68
|
+
- `url(options)`: 認証URLを生成
|
|
69
|
+
- `token(code)`: 認可コードをトークンと交換
|
|
70
|
+
- `refresh(refreshToken)`: アクセストークンをリフレッシュ
|
|
59
71
|
|
|
60
72
|
### User
|
|
61
73
|
|
|
62
74
|
Googleユーザー情報を取得するクラス。
|
|
63
75
|
|
|
64
|
-
- `profile(
|
|
65
|
-
- `detailedProfile(
|
|
66
|
-
- `verifyToken(
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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)
|