google-oauth-lib
v1.0.6
Published
Google OAuth Provider for Node.js
Maintainers
Readme
google-oauth-lib
Node.js向けのGoogle OAuth 2.0認証ライブラリ。TypeScriptで書かれ、完全な型定義を提供します。
特徴
- OAuth 2.0完全対応: Google OAuthの全機能をサポート(予定)
- TypeScript対応: 完全な型定義付きで開発効率向上
- シンプルなAPI: 直感的なインターフェース
- 拡張性: Google APIsへの対応も計画中
- OSS: オープンソースでコミュニティ貢献歓迎
インストール
npm install google-oauth-libクイックスタート
import { Google } from "google-oauth-lib";
// 設定
const config = {
clientId: process.env.GOOGLE_CLIENT_ID || "",
clientSecret: process.env.GOOGLE_CLIENT_SECRET || "",
authorization: {
params: {
scope: [
"openid",
"email",
"profile"
]
}
}
};
// Googleクライアント作成
const google = Google.OAuth(config);
// 認証URL生成
const authUrl = google.oauth.url({
redirect_uri: "http://localhost:3000"
});
// トークン取得(コールバック後)
const tokens = await google.oauth.token(code);
// ユーザー情報取得
const profile = await google.user.profile();API リファレンス
OAuth2
Google OAuth 2.0認証を扱うクラス。
url(options): 認証URLを生成token(code): 認可コードをトークンと交換refresh(refreshToken): アクセストークンをリフレッシュ
User
Googleユーザー情報を取得するクラス。
profile(): 基本ユーザー情報を取得detailedProfile(): People APIで詳細情報を取得verifyToken(): トークンの有効性を検証
Google (メインクラス)
OAuthとUserを統合したメインクラス。
const google = Google.OAuth(config);設定
interface GoogleProviderConfig {
clientId: string;
clientSecret: string;
redirectUri: string;
}開発
ビルド
npm run buildテスト
npm testロードマップ
- [x] OAuth 2.0基本認証
- [ ] OAuth 2.0完全対応(全スコープ、PKCEなど)
- [ ] Google APIs統合(Drive, Gmail, Calendarなど)
- [ ] ドキュメント充実
- [ ] テスト追加
貢献
このプロジェクトはOSSです。IssueやPull Requestを歓迎します!
- Fork
- Feature branch作成 (
git checkout -b feature/AmazingFeature) - コミット (
git commit -m 'Add some AmazingFeature') - Push (
git push origin feature/AmazingFeature) - Pull Request
ライセンス
ISC License
