@kiauth/web-sdk 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.
- package/README.md +109 -0
- package/dist/kiauth-sdk.js +3684 -0
- package/dist/kiauth-sdk.js.map +1 -0
- package/dist/kiauth-sdk.min.js +3692 -0
- package/dist/kiauth-sdk.min.js.map +1 -0
- package/dist/types/Button.d.ts +6 -0
- package/dist/types/Fallback.d.ts +20 -0
- package/dist/types/KiauthSDK.d.ts +71 -0
- package/dist/types/QrModal.d.ts +7 -0
- package/dist/types/Websocket.d.ts +21 -0
- package/dist/types/api.d.ts +65 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.umd.d.ts +2 -0
- package/dist/types/pkce.d.ts +8 -0
- package/dist/types/styles.d.ts +2 -0
- package/dist/types/types.d.ts +47 -0
- package/package.json +28 -0
package/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# @kiauth/web-sdk
|
|
2
|
+
|
|
3
|
+
Framework-agnostic "Login with Kiauth" button for any website (React, Vue, Angular,
|
|
4
|
+
Svelte, or plain HTML). Renders a button, runs the QR approval flow, and hands your
|
|
5
|
+
frontend a one-time authorization `code`. Your **server** exchanges that code for the
|
|
6
|
+
verified user.
|
|
7
|
+
|
|
8
|
+
> Test backend: `https://api.kiauth.com` — pass it as `baseUrl`.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
**Option A — script tag (no build tooling):**
|
|
13
|
+
```html
|
|
14
|
+
<script src="/path/to/kiauth-sdk.min.js"></script>
|
|
15
|
+
<script>
|
|
16
|
+
const kiauth = new KiauthSDK({
|
|
17
|
+
clientId: 'YOUR_CLIENT_ID',
|
|
18
|
+
scopes: ['name', 'email'],
|
|
19
|
+
environment: 'production',
|
|
20
|
+
baseUrl: 'https://api.kiauth.com'
|
|
21
|
+
});
|
|
22
|
+
kiauth.renderButton('#login-container', {
|
|
23
|
+
text: 'Login with Kiauth',
|
|
24
|
+
onSuccess: (user) => {
|
|
25
|
+
// user.code -> send to YOUR backend to exchange (see below)
|
|
26
|
+
},
|
|
27
|
+
onError: (err) => console.error(err.message)
|
|
28
|
+
});
|
|
29
|
+
</script>
|
|
30
|
+
<div id="login-container"></div>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Option B — local tarball (import workflow):**
|
|
34
|
+
```bash
|
|
35
|
+
npm install ./kiauth-web-sdk-1.0.0.tgz
|
|
36
|
+
```
|
|
37
|
+
```js
|
|
38
|
+
import { KiauthSDK } from '@kiauth/web-sdk';
|
|
39
|
+
|
|
40
|
+
const kiauth = new KiauthSDK({
|
|
41
|
+
clientId: process.env.KIAUTH_CLIENT_ID,
|
|
42
|
+
scopes: ['name', 'email'],
|
|
43
|
+
environment: 'production',
|
|
44
|
+
baseUrl: 'https://api.kiauth.com'
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Config
|
|
49
|
+
|
|
50
|
+
| Field | Required | Notes |
|
|
51
|
+
|---|---|---|
|
|
52
|
+
| `clientId` | yes | From your app in the Kiauth dev portal |
|
|
53
|
+
| `scopes` | yes | Subset of `name`, `email`, `dob`, `gender`, `phone` |
|
|
54
|
+
| `environment` | yes | `'production'` or `'sandbox'` |
|
|
55
|
+
| `baseUrl` | recommended | Backend URL. Overrides the env default. `/api/v1` is appended automatically. |
|
|
56
|
+
| `redirectUri` | optional | Where to return after approval |
|
|
57
|
+
|
|
58
|
+
## Button customization (white-label)
|
|
59
|
+
|
|
60
|
+
`renderButton(selector, options)` accepts optional styling so the button can match
|
|
61
|
+
your brand. All are optional and backward-compatible (omit them for the default look).
|
|
62
|
+
|
|
63
|
+
| Option | Type | Notes |
|
|
64
|
+
|---|---|---|
|
|
65
|
+
| `text` | string | Button label (default `"Login with Kiauth"`) |
|
|
66
|
+
| `theme` | `'purple' \| 'white' \| 'dark'` | Preset look |
|
|
67
|
+
| `size` | `'small' \| 'medium' \| 'large'` | |
|
|
68
|
+
| `color` | string (CSS color) | Custom background/brand color — overrides `theme` |
|
|
69
|
+
| `textColor` | string (CSS color) | Custom label + icon color |
|
|
70
|
+
| `shape` | `'rounded' \| 'pill' \| 'square'` | Corner style |
|
|
71
|
+
| `fullWidth` | boolean | Stretch to the container width |
|
|
72
|
+
| `logo` | boolean | Show the Kiauth lock mark (default `true`) |
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
kiauth.renderButton('#login-container', {
|
|
76
|
+
text: 'Continue with Kiauth',
|
|
77
|
+
color: '#0F172A',
|
|
78
|
+
textColor: '#FFFFFF',
|
|
79
|
+
shape: 'pill',
|
|
80
|
+
fullWidth: true,
|
|
81
|
+
onSuccess: (user) => { /* ... */ },
|
|
82
|
+
onError: (err) => console.error(err.message)
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
> Prefer a redirect-based integration with your existing auth library (Auth.js, etc.)?
|
|
87
|
+
> Kiauth is also a standard **OpenID Connect** provider — see the dev-portal docs for the
|
|
88
|
+
> "Login with Kiauth" OIDC option. The embedded button (this SDK) gives full white-label
|
|
89
|
+
> control; OIDC is the lowest-friction drop-in.
|
|
90
|
+
|
|
91
|
+
## Server-side token exchange (required)
|
|
92
|
+
|
|
93
|
+
The `code` from `onSuccess` is exchanged on **your backend** — never expose your Client Secret in the browser.
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
const res = await fetch('https://api.kiauth.com/api/v1/auth/token', {
|
|
97
|
+
method: 'POST',
|
|
98
|
+
headers: { 'Content-Type': 'application/json' },
|
|
99
|
+
body: JSON.stringify({
|
|
100
|
+
grantType: 'authorization_code',
|
|
101
|
+
code,
|
|
102
|
+
clientId: process.env.KIAUTH_CLIENT_ID,
|
|
103
|
+
clientSecret: process.env.KIAUTH_CLIENT_SECRET
|
|
104
|
+
})
|
|
105
|
+
});
|
|
106
|
+
const { user } = await res.json(); // { name, email, verified, userToken }
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Use `user.userToken` (a stable per-user id) to create your own app session.
|