oauth.do 0.1.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/README.md +126 -0
- package/dist/cli.js +800 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +305 -0
- package/dist/index.js +637 -0
- package/dist/index.js.map +1 -0
- package/package.json +68 -0
- package/src/mdx/hooks.mdx +119 -0
package/README.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# oauth.do
|
|
2
|
+
|
|
3
|
+
OAuth authentication SDK and CLI for .do Platform.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install oauth.do
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## CLI
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx oauth.do # Login (default)
|
|
15
|
+
npx oauth.do login # Login with device flow
|
|
16
|
+
npx oauth.do logout # Logout
|
|
17
|
+
npx oauth.do whoami # Show current user
|
|
18
|
+
npx oauth.do token # Display token
|
|
19
|
+
npx oauth.do status # Show auth status
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## SDK
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { auth, login, logout, getToken, isAuthenticated } from 'oauth.do'
|
|
26
|
+
|
|
27
|
+
// Check authentication
|
|
28
|
+
const { user, token } = await auth()
|
|
29
|
+
|
|
30
|
+
// Login
|
|
31
|
+
const result = await login({ email: '...', password: '...' })
|
|
32
|
+
|
|
33
|
+
// Logout
|
|
34
|
+
await logout(token)
|
|
35
|
+
|
|
36
|
+
// Get stored token
|
|
37
|
+
const token = getToken()
|
|
38
|
+
|
|
39
|
+
// Check if authenticated
|
|
40
|
+
if (await isAuthenticated()) { ... }
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Build Auth URL
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { buildAuthUrl } from 'oauth.do'
|
|
47
|
+
|
|
48
|
+
const url = buildAuthUrl({
|
|
49
|
+
redirectUri: 'https://myapp.com/callback',
|
|
50
|
+
scope: 'openid profile email',
|
|
51
|
+
})
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Device Authorization Flow
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { authorizeDevice, pollForTokens } from 'oauth.do'
|
|
58
|
+
|
|
59
|
+
const auth = await authorizeDevice()
|
|
60
|
+
console.log('Visit:', auth.verification_uri)
|
|
61
|
+
console.log('Code:', auth.user_code)
|
|
62
|
+
|
|
63
|
+
const tokens = await pollForTokens(auth.device_code, auth.interval, auth.expires_in)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## API Keys
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { createApiKey, listApiKeys, rotateApiKey, deleteApiKey } from 'oauth.do'
|
|
70
|
+
|
|
71
|
+
// Create
|
|
72
|
+
const key = await createApiKey({ name: 'my-key', expiresIn: '30d' })
|
|
73
|
+
|
|
74
|
+
// List
|
|
75
|
+
const keys = await listApiKeys()
|
|
76
|
+
|
|
77
|
+
// Rotate
|
|
78
|
+
const newKey = await rotateApiKey(key.id)
|
|
79
|
+
|
|
80
|
+
// Delete
|
|
81
|
+
await deleteApiKey(key.id)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Token Storage
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { createSecureStorage, KeychainTokenStorage } from 'oauth.do'
|
|
88
|
+
|
|
89
|
+
// Auto-select best storage (keychain → secure file)
|
|
90
|
+
const storage = createSecureStorage()
|
|
91
|
+
|
|
92
|
+
// Or use keychain directly
|
|
93
|
+
const keychain = new KeychainTokenStorage()
|
|
94
|
+
if (await keychain.isAvailable()) {
|
|
95
|
+
await keychain.setToken('...')
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Storage backends:
|
|
100
|
+
- `KeychainTokenStorage` - OS keychain (macOS, Windows, Linux)
|
|
101
|
+
- `SecureFileTokenStorage` - ~/.oauth.do/token with 0600 permissions
|
|
102
|
+
- `MemoryTokenStorage` - In-memory (testing)
|
|
103
|
+
- `LocalStorageTokenStorage` - Browser localStorage
|
|
104
|
+
|
|
105
|
+
## Configuration
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { configure } from 'oauth.do'
|
|
109
|
+
|
|
110
|
+
configure({
|
|
111
|
+
apiUrl: 'https://apis.do',
|
|
112
|
+
clientId: 'your-client-id',
|
|
113
|
+
authKitDomain: 'login.oauth.do'
|
|
114
|
+
})
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Environment Variables
|
|
118
|
+
|
|
119
|
+
- `DO_TOKEN` - Authentication token
|
|
120
|
+
- `OAUTH_API_URL` - API base URL (default: `https://apis.do`)
|
|
121
|
+
- `OAUTH_CLIENT_ID` - OAuth client ID (default: `oauth.do`)
|
|
122
|
+
- `OAUTH_AUTHKIT_DOMAIN` - AuthKit domain (default: `login.oauth.do`)
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
MIT
|