@htmlbricks/hb-auth-social-login-button 0.71.35 → 0.71.36

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 (3) hide show
  1. package/README.md +133 -29
  2. package/manifest.json +17 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,48 +1,152 @@
1
- ## `hb-auth-social-login-button` — auth-social-login-button
1
+ # `hb-auth-social-login-button`
2
2
 
3
- **Category:** auth | **Tags:** auth, oauth
3
+ ## Summary
4
4
 
5
- ### What it does
5
+ Web component: a square, keyboard-accessible control that starts an OAuth-style redirect for a configured provider (built-in SVGs for GitLab, GitHub, Facebook, Google, and Authentik), or emits a custom event when the provider cannot be started from built-in URL rules. On return to the same page, it can detect tokens or codes in `location.href` and exchange them via `simple-serverless-auth-client` when a server URL and cookie name are set.
6
6
 
7
- Clickable OAuth provider tile (default SVGs for Google, GitHub, GitLab, Facebook, Authentik; overridable via slot). Builds the provider authorization URL from `provider` params or uses a prebuilt `url`, then parses the return URL to exchange code/token with `simple-serverless-auth-client` when `social_auth_server_url` and `auth_cookie_name` are set. Emits `oauthFlowRedirectStart` immediately before redirecting to the provider, then `oauthFlowInit`, `oauthFlowSuccess`, or `oauthFlowCustom` for custom flows.
7
+ ## What it does
8
8
 
9
- ### Custom element
9
+ - Renders a clickable `#icon-content` region (`role="button"`, `tabindex="0"`) that runs `socialLogin()` on click or Enter/Space.
10
+ - If `provider.url` is set, dispatches `oauthFlowRedirectStart` and sets `location.href` to that URL.
11
+ - Else, if `provider.params` includes `client_id` and `redirect_url`, builds a provider-specific authorize URL (see Logic), dispatches `oauthFlowRedirectStart`, then redirects.
12
+ - Else logs a warning and dispatches `oauthFlowCustom`.
13
+ - On mount, `detectByUri()` inspects `location.href` for provider-specific return patterns; when matched, dispatches `oauthFlowInit` and may call `Authorize.socialLoginOauthAnswer` if both `social_auth_server_url` and `auth_cookie_name` are truthy. On success, either navigates to `redirectonlogin` or dispatches `oauthFlowSuccess` with `{ token }`.
10
14
 
11
- `hb-auth-social-login-button`
15
+ ## Appearance
12
16
 
13
- ### Attributes / props (snake_case)
17
+ | Aspect | Behavior |
18
+ | --- | --- |
19
+ | Host | `display: block`, fixed size `2.5rem` × `2.5rem`, padding `0.625rem`. |
20
+ | `#icon` | Fills host, transparent background, `position: relative`. |
21
+ | `#icon-content` | Absolutely positioned, vertically centered, `cursor: pointer`, transparent background. |
22
+ | Default artwork | Inline SVGs with `part="provider_icon"` for known `provider.name` values; unknown name shows literal text `btn` inside the default slot fallback. |
23
+ | Focus | `:focus-visible` uses outline and radius from CSS variables (see Styling). |
14
24
 
15
- | Property | Type | Notes |
25
+ ## Logic
26
+
27
+ | Step | Condition | Action |
16
28
  | --- | --- | --- |
17
- | `id` | string (optional) | Element identifier. |
18
- | `style` | string (optional) | Inline style string. |
19
- | `social_auth_server_url` | string (optional) | Server URL for token exchange. |
20
- | `auth_cookie_name` | string (optional) | Cookie name used by the auth client. |
21
- | `redirectonlogin` | string (optional) | Post-login redirect. |
22
- | `provider` | object (optional) | JSON: `{ url?: string; name: "facebook" \| "google" \| "gitlab" \| "github" \| "authentik"; params?: { redirect_url; client_id; scope; auth_server_url? } }`. |
29
+ | Parse `provider` | `provider` is a string | `JSON.parse` in an `$effect` (errors logged to console). |
30
+ | Start login | Missing `provider.name`, or both `provider.url` and `provider.params` missing | `console.error`, return. |
31
+ | Prebuilt URL | `provider.url` set | `oauthFlowRedirectStart`, then `location.href = provider.url`. |
32
+ | Composed URL | `provider.params.client_id` and `provider.params.redirect_url` | Build URL by `provider.name`, then `oauthFlowRedirectStart` and redirect. |
33
+ | No URL | Otherwise | `console.warn`, `oauthFlowCustom`. |
34
+ | Google URL | `google` | `https://accounts.google.com/o/oauth2/v2/auth` with `response_type=token`, `scope`, `client_id`, `redirect_uri`, etc. |
35
+ | GitHub URL | `github` | `https://github.com/login/oauth/authorize` with `scope`, `client_id`, `redirect_uri`. |
36
+ | GitLab URL | `gitlab` | `https://gitlab.com/oauth/authorize` with `response_type=code`, `state`, `scope`, `client_id`, `redirect_uri`. |
37
+ | Facebook URL | `facebook` | Same host/path pattern as GitLab in code: `https://gitlab.com/oauth/authorize?...` (same query shape as `gitlab`). |
38
+ | Authentik URL | `authentik` | `` `${provider.params.auth_server_url}/application/o/authorize/?` `` plus `scope`, `response_type=code`, `state`, `client_id`, `redirect_uri`. |
39
+ | Return: Google | `provider.name === "google"`, URL contains `access_token=` and `google` | Extract token after `access_token=`, call server exchange with `{ provider, token }`, dispatch `oauthFlowInit` with `{ provider, token }`. |
40
+ | Return: GitHub | `github`, `code=`, `provider=github` | Code as `token` / `tmpCode`, server exchange, `oauthFlowInit` with `token` and `tmpCode`. |
41
+ | Return: Facebook | `facebook`, `code=`, `provider=facebook` | Derives `redirect_uri` by stripping `state` and `code` segments from `location.href`, server exchange, `oauthFlowInit` includes `redirect_uri`. |
42
+ | Return: GitLab | `gitlab`, `code=`, `provider=gitlab` | Same style of `redirect_uri` derivation and `oauthFlowInit` as other code-based providers. |
43
+ | Return: Authentik | `authentik`, `code=`, `provider=authentik` | Same pattern as GitLab/Facebook for exchange and `oauthFlowInit`. |
44
+ | Server exchange | `auth_cookie_name` and `social_auth_server_url` both truthy | `Authorize.socialLoginOauthAnswer(providerPayload, { authUrl: social_auth_server_url, authCookieName: auth_cookie_name })`. |
45
+ | After exchange | `redirectonlogin` truthy | `location.href = redirectonlogin`. |
46
+ | After exchange | No `redirectonlogin` | `oauthFlowSuccess` with `{ token: resolvedToken }`. |
47
+
48
+ ## Custom element
49
+
50
+ | Tag |
51
+ | --- |
52
+ | `hb-auth-social-login-button` |
53
+
54
+ ## Attributes
55
+
56
+ Web component attributes are strings; complex values use JSON strings. Boolean-like project rules elsewhere do not apply to the props used here beyond normal string attributes.
57
+
58
+ | Attribute | Role in code |
59
+ | --- | --- |
60
+ | `id` | Bound to `id`; default `""` in destructuring. |
61
+ | `provider` | Provider config; coerced from JSON string if passed as string. Must include `name` and either `url` or `params` (see Logic). |
62
+ | `social_auth_server_url` | Passed to `Authorize.socialLoginOauthAnswer` as `authUrl` when set with `auth_cookie_name`. |
63
+ | `auth_cookie_name` | Passed as `authCookieName`; default `"hb_session"` in destructuring. |
64
+ | `redirectonlogin` | If set after successful exchange, full-page redirect to this URL instead of emitting `oauthFlowSuccess`. |
23
65
 
24
- **Slots:** `default` (custom icon or label). **CSS parts:** `provider_icon` on built-in provider SVGs. **i18n:** Italian and English in metadata.
66
+ The TypeScript `Component` type also includes optional `style`, which is not read from `$props()` in `component.wc.svelte` (the `style` binding is commented out).
25
67
 
26
- ### Events (`CustomEvent` names)
68
+ ## Events
27
69
 
28
- - **`oauthFlowSuccess`** `{ token: string }`
29
- - **`oauthFlowRedirectStart`** — `{ provider: IProvider }` (`IProvider` = facebook \| google \| gitlab \| github \| authentik)
30
- - **`oauthFlowInit`** — `{ token?: string; provider: IProvider; tmpCode?: string; redirect_uri?: string }`
31
- - **`oauthFlowCustom`** — `{ provider: IProvider }`
70
+ All events are `CustomEvent` dispatched on the host element.
32
71
 
33
- ### Usage notes
72
+ | Event | `detail` |
73
+ | --- | --- |
74
+ | `oauthFlowRedirectStart` | `{ provider: IProvider }` |
75
+ | `oauthFlowInit` | `{ token?: string; provider: IProvider; tmpCode?: string; redirect_uri?: string }` |
76
+ | `oauthFlowSuccess` | `{ token: string }` |
77
+ | `oauthFlowCustom` | `{ provider: IProvider }` |
78
+
79
+ `IProvider` in types: `"facebook" \| "google" \| "gitlab" \| "github" \| "authentik"`.
80
+
81
+ ## Styling (vars / parts / slots)
82
+
83
+ ### CSS custom properties
84
+
85
+ | Variable | Used in | Fallback in SCSS |
86
+ | --- | --- | --- |
87
+ | `--bulma-link` | `#icon-content:focus-visible` outline color | `#485fc7` |
88
+ | `--bulma-radius` | `#icon-content:focus-visible` border radius | `0.25rem` |
34
89
 
35
- - Bulma theme variables (`--bulma-*`) apply where the host uses Bulma.
36
- - Provider artwork aligns with common OAuth brands; the default slot can replace the built-in SVGs.
37
- - Built-in SVGs use a transparent background and export **`::part(provider_icon)`** so the parent page can style the icon (size, `filter`, etc.).
38
- - Use `i18nlang` on parent `hb-auth` or this component’s i18n metadata where wired.
90
+ ### `::part`
39
91
 
40
- ### Minimal HTML example
92
+ | Part | Target |
93
+ | --- | --- |
94
+ | `provider_icon` | Default provider `<svg>` elements (`part="provider_icon"`). |
95
+
96
+ ### Slots
97
+
98
+ | Slot | Description |
99
+ | --- | --- |
100
+ | `default` | Replaces default slot content (built-in SVGs or the `btn` fallback). Use for custom artwork or label inside the control. |
101
+
102
+ ## TypeScript
103
+
104
+ Authoring types live in `types/webcomponent.type.d.ts`:
105
+
106
+ ```ts
107
+ type IProvider = "facebook" | "google" | "gitlab" | "github" | "authentik";
108
+
109
+ export type Component = {
110
+ id?: string;
111
+ style?: string;
112
+ social_auth_server_url?: string;
113
+ auth_cookie_name?: string;
114
+ redirectonlogin?: string;
115
+ provider:
116
+ | {
117
+ url?: string;
118
+ name: IProvider;
119
+ params?: {
120
+ redirect_url: string;
121
+ client_id: string;
122
+ scope: string;
123
+ auth_server_url?: string;
124
+ };
125
+ }
126
+ | undefined;
127
+ };
128
+
129
+ export type Events = {
130
+ oauthFlowSuccess: { token: string };
131
+ oauthFlowInit: {
132
+ token?: string;
133
+ provider: IProvider;
134
+ tmpCode?: string;
135
+ redirect_uri?: string;
136
+ };
137
+ oauthFlowRedirectStart: { provider: IProvider };
138
+ oauthFlowCustom: { provider: IProvider };
139
+ };
140
+ ```
141
+
142
+ ## Minimal example
41
143
 
42
144
  ```html
43
145
  <hb-auth-social-login-button
44
- provider='{"name":"google","url":"https://accounts.google.com/o/oauth2/v2/auth?..."}'
45
- social_auth_server_url="https://auth.example.com"
46
- auth_cookie_name="session"
146
+ provider='{"name":"google","url":"https://accounts.google.com/o/oauth2/v2/auth?client_id=YOUR_CLIENT&redirect_uri=YOUR_REDIRECT&response_type=token&scope=openid%20email"}'
147
+ social_auth_server_url="https://your-auth.example"
148
+ auth_cookie_name="hb_session"
47
149
  ></hb-auth-social-login-button>
48
150
  ```
151
+
152
+ Using composed params instead of `url` requires at least `name`, `params.client_id`, `params.redirect_url`, and `params.scope` so the component can build the authorize URL before redirecting.
package/manifest.json CHANGED
@@ -183,11 +183,24 @@
183
183
  }
184
184
  },
185
185
  "styleSetup": {
186
- "vars": [],
186
+ "vars": [
187
+ {
188
+ "name": "--bulma-link",
189
+ "valueType": "color",
190
+ "defaultValue": "#485fc7",
191
+ "description": "Focus-visible outline on the clickable icon area (`#icon-content`)."
192
+ },
193
+ {
194
+ "name": "--bulma-radius",
195
+ "valueType": "number",
196
+ "defaultValue": "0.375rem",
197
+ "description": "Border radius for the focus ring around the icon control."
198
+ }
199
+ ],
187
200
  "parts": [
188
201
  {
189
202
  "name": "provider_icon",
190
- "description": "Default built-in provider SVG (GitLab, GitHub, Facebook, Google, Authentik). Exposed so the host can adjust size, filters, or colors (e.g. `hb-auth-social-login-button::part(provider_icon) { ... }`)."
203
+ "description": "Built-in provider SVG (Google, GitHub, GitLab, Facebook, Authentik). Style size, `filter`, or color from the light DOM (e.g. `hb-auth-social-login-button::part(provider_icon)`)."
191
204
  }
192
205
  ]
193
206
  },
@@ -195,7 +208,7 @@
195
208
  "htmlSlots": [
196
209
  {
197
210
  "name": "default",
198
- "description": "Custom provider icon or label inside the login control."
211
+ "description": "Replace the default provider artwork or add a custom label inside the square control; used when you do not rely on the built-in SVG set."
199
212
  }
200
213
  ],
201
214
  "i18n": [
@@ -265,5 +278,5 @@
265
278
  },
266
279
  "iifePath": "main.iife.js",
267
280
  "repoName": "@htmlbricks/hb-auth-social-login-button",
268
- "version": "0.71.35"
281
+ "version": "0.71.36"
269
282
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htmlbricks/hb-auth-social-login-button",
3
- "version": "0.71.35",
3
+ "version": "0.71.36",
4
4
  "contributors": [],
5
5
  "description": "Clickable OAuth provider tile (default SVGs for Google, GitHub, GitLab, Facebook, Authentik; overridable via slot). Builds the provider authorization URL from `provider` params or redirects to a prebuilt `url`, then on return parses the current page URL to exchange the code/token with `simple-serverless-auth-client` when `social_auth_server_url` and `auth_cookie_name` are set. Emits `oauthFlowRedirectStart` immediately before leaving for the provider, then `oauthFlowInit`, `oauthFlowSuccess`, or `oauthFlowCustom` as the flow progresses.",
6
6
  "licenses": [