@htmlbricks/hb-auth-social-login-button 0.71.32 → 0.71.34
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 +3 -2
- package/main.iife.js +1 -1
- package/main.iife.js.map +1 -1
- package/manifest.json +20 -3
- package/package.json +2 -2
- package/types/webcomponent.type.d.ts +2 -0
- package/types/webcomponent_events.type.d.json +14 -0
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
### What it does
|
|
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 `oauthFlowInit`, `oauthFlowSuccess`, or `oauthFlowCustom` for custom flows.
|
|
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.
|
|
8
8
|
|
|
9
9
|
### Custom element
|
|
10
10
|
|
|
@@ -26,7 +26,8 @@ Clickable OAuth provider tile (default SVGs for Google, GitHub, GitLab, Facebook
|
|
|
26
26
|
### Events (`CustomEvent` names)
|
|
27
27
|
|
|
28
28
|
- **`oauthFlowSuccess`** — `{ token: string }`
|
|
29
|
-
- **`
|
|
29
|
+
- **`oauthFlowRedirectStart`** — `{ provider: IProvider }` (`IProvider` = facebook \| google \| gitlab \| github \| authentik)
|
|
30
|
+
- **`oauthFlowInit`** — `{ token?: string; provider: IProvider; tmpCode?: string; redirect_uri?: string }`
|
|
30
31
|
- **`oauthFlowCustom`** — `{ provider: IProvider }`
|
|
31
32
|
|
|
32
33
|
### Usage notes
|
package/main.iife.js
CHANGED
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
* Load after Bulma theme in the component style block so \`--bulma-*\` tokens apply.
|
|
40
40
|
*/:host {box-sizing:border-box;max-width:100%;font-family:var(--bulma-family-primary, "Inter", "Segoe UI", "Roboto", "Helvetica Neue", "Arial", sans-serif);}.svelte-4zfj79,
|
|
41
41
|
.svelte-4zfj79::before,
|
|
42
|
-
.svelte-4zfj79::after {box-sizing:inherit;}:host {display:block;width:2.5rem;height:2.5rem;padding:0.625rem;}#icon.svelte-4zfj79 {width:100%;height:100%;position:relative;}#icon-content.svelte-4zfj79 {margin:0;position:absolute;inset-block-start:50%;inset-inline:0;transform:translateY(-50%);cursor:pointer;}#icon-content.svelte-4zfj79:focus-visible {outline:2px solid var(--bulma-link, #485fc7);outline-offset:2px;border-radius:var(--bulma-radius, 0.25rem);}`};function Sr(e,t){Re(t,!0),or(e,xr);function n(e,n){t.$$host.dispatchEvent(new CustomEvent(e,{detail:n}))}let r=sr(t,`provider`,7,void 0),i=sr(t,`auth_cookie_name`,7,`hb_session`),a=sr(t,`social_auth_server_url`,7,void 0),o=sr(t,`redirectonlogin`,7,void 0),s=sr(t,`id`,7,``);Zt(()=>{if(typeof r()==`string`)try{r(JSON.parse(r()))}catch(e){console.error(e)}});async function c(){if(!r()?.name||!r().url&&!r().params)return console.error(`Provider not defined`);if(r().url)location.href=r().url;else if(r().params?.client_id&&r().params.redirect_url){if(!r().params.client_id||!r().params.redirect_url)return console.error(`Missing client_id or redirect_url in oauth2ProvidersObj`);let e;switch(r().name){case`google`:e=`https://accounts.google.com/o/oauth2/v2/auth?scope=${r().params.scope}&include_granted_scopes=true&response_type=token&state=state_parameter_passthrough_value&client_id=${r().params.client_id}&redirect_uri=${r().params.redirect_url}`;break;case`github`:e=`https://github.com/login/oauth/authorize?scope=${r().params.scope}&client_id=${r().params.client_id}&redirect_uri=${r().params.redirect_url}`;break;case`gitlab`:e=`https://gitlab.com/oauth/authorize?scope=${r().params.scope}&response_type=code&state=${new Date().valueOf()}&client_id=${r().params.client_id}&redirect_uri=${r().params.redirect_url}`;break;case`facebook`:e=`https://gitlab.com/oauth/authorize?scope=${r().params.scope}&response_type=code&state=${new Date().valueOf()}&client_id=${r().params.client_id}&redirect_uri=${r().params.redirect_url}`;break;case`authentik`:e=`${r().params.auth_server_url}/application/o/authorize/?scope=${r().params.scope}&response_type=code&state=${new Date().valueOf()}&client_id=${r().params.client_id}&redirect_uri=${r().params.redirect_url}`;break;default:return console.error(`no provider uri composed for `+r().name)}if(e)location.href=e;else return console.error(`no provider url obtained!?`,r())}else console.warn(`no provider uri or params defined for `+r().name),n(`oauthFlowCustom`,{provider:r().name})}function l(e){i()&&a()&&mr.socialLoginOauthAnswer(e,{authUrl:a(),authCookieName:i()}).then(e=>{console.log(`auth from client`,e),o()?location.href=o():(console.log(`oauthFlowSuccess now`,{token:e}),n(`oauthFlowSuccess`,{token:e}))}).catch(e=>{console.error(`flowerr`,e)})}function u(){if(console.info(`detecting by uri`,location.href),r()?.name){if(r().name===`google`&&location?.href&&location.href.split(`access_token=`).length>1&&location.href.includes(`google`)){console.info(`google auth login detected`);let e=location.href.split(`access_token=`)[1].split(`&`)[0];l({provider:r().name,token:e}),n(`oauthFlowInit`,{provider:r().name,token:e})}if(r().name===`github`&&location?.href&&location.href.includes(`code=`)&&location.href.includes(`provider=`)&&location.href.split(`provider=`)[1].split(`&`)[0]===`github`){console.info(`github auth login detected`);let e=location.href.split(`code=`)[1].split(`&`)[0];l({provider:r().name,token:e,tmpCode:e}),n(`oauthFlowInit`,{provider:r().name,token:e,tmpCode:e})}if(r().name===`facebook`&&location?.href&&location.href.includes(`code=`)&&location.href.includes(`provider=`)&&location.href.split(`provider=`)[1].split(`&`)[0]===`facebook`){console.info(`facebook auth login detected`);let e=location.href.split(`code=`)[1].split(`&`)[0],t=location.href.split(`state=`)[1].split(`&`)[0],i=location.href.replace(`&state=`,``).replace(`?state=`,``).replace(`&code=`,``).replace(`?code=`,``).replace(e,``).replace(t,``);l({provider:r().name,token:e,tmpCode:e,redirect_uri:i}),n(`oauthFlowInit`,{provider:r().name,token:e,tmpCode:e,redirect_uri:i})}if(r().name===`gitlab`&&location?.href&&location.href.includes(`provider=`)&&location.href.includes(`code=`)&&location.href.split(`provider=`)[1].split(`&`)[0]===`gitlab`){let e=location.href.split(`code=`)[1].split(`&`)[0],t=location.href.split(`state=`)[1].split(`&`)[0],i=location.href.replace(`&state=`,``).replace(`?state=`,``).replace(`&code=`,``).replace(`?code=`,``).replace(e,``).replace(t,``);l({provider:r().name,token:e,tmpCode:e,redirect_uri:i}),n(`oauthFlowInit`,{provider:r().name,token:e,tmpCode:e,redirect_uri:location.href.replace(`&state=`,``).replace(`?state=`,``).replace(`&code=`,``).replace(`?code=`,``).replace(e,``).replace(t,``)})}if(r().name===`authentik`&&location?.href&&location.href.includes(`provider=`)&&location.href.includes(`code=`)&&location.href.split(`provider=`)[1].split(`&`)[0]===`authentik`){console.info(`authentik auth login detected`);let e=location.href.split(`code=`)[1].split(`&`)[0],t=location.href.split(`state=`)[1].split(`&`)[0],i=location.href.replace(`&state=`,``).replace(`?state=`,``).replace(`&code=`,``).replace(`?code=`,``).replace(e,``).replace(t,``);l({provider:r().name,token:e,tmpCode:e,redirect_uri:i}),n(`oauthFlowInit`,{provider:r().name,token:e,tmpCode:e,redirect_uri:i})}}}nr(()=>{u()});var d={get provider(){return r()},set provider(e=void 0){r(e),st()},get auth_cookie_name(){return i()},set auth_cookie_name(e=`hb_session`){i(e),st()},get social_auth_server_url(){return a()},set social_auth_server_url(e=void 0){a(e),st()},get redirectonlogin(){return o()},set redirectonlogin(e=void 0){o(e),st()},get id(){return s()},set id(e=``){s(e),st()}},f=br(),p=Vt(f);return ar(Vt(p),t,`default`,{},e=>{var t=Kn(),n=Ht(t),i=e=>{$(e,hr())},a=e=>{$(e,gr())},o=e=>{$(e,_r())},s=e=>{$(e,vr())},c=e=>{$(e,yr())},l=e=>{$(e,Gn(`btn`))};ir(n,e=>{r()?.name===`gitlab`?e(i):r()?.name===`github`?e(a,1):r()?.name===`facebook`?e(o,2):r()?.name===`google`?e(s,3):r()?.name===`authentik`?e(c,4):e(l,-1)}),$(e,t)}),ke(p),ke(f),Fn(`click`,p,()=>{c()}),Fn(`keydown`,p,e=>{(e.key===`Enter`||e.key===` `)&&c()}),$(e,f),ze(d)}In([`click`,`keydown`]),customElements.define(`hb-auth-social-login-button`,pr(Sr,{provider:{},auth_cookie_name:{},social_auth_server_url:{},redirectonlogin:{},id:{}},[`default`],[],{mode:`open`})),e.Component=Sr})(this[`auth-social-login-button`]=this[`auth-social-login-button`]||{});
|
|
42
|
+
.svelte-4zfj79::after {box-sizing:inherit;}:host {display:block;width:2.5rem;height:2.5rem;padding:0.625rem;}#icon.svelte-4zfj79 {width:100%;height:100%;position:relative;}#icon-content.svelte-4zfj79 {margin:0;position:absolute;inset-block-start:50%;inset-inline:0;transform:translateY(-50%);cursor:pointer;}#icon-content.svelte-4zfj79:focus-visible {outline:2px solid var(--bulma-link, #485fc7);outline-offset:2px;border-radius:var(--bulma-radius, 0.25rem);}`};function Sr(e,t){Re(t,!0),or(e,xr);function n(e,n){t.$$host.dispatchEvent(new CustomEvent(e,{detail:n}))}let r=sr(t,`provider`,7,void 0),i=sr(t,`auth_cookie_name`,7,`hb_session`),a=sr(t,`social_auth_server_url`,7,void 0),o=sr(t,`redirectonlogin`,7,void 0),s=sr(t,`id`,7,``);Zt(()=>{if(typeof r()==`string`)try{r(JSON.parse(r()))}catch(e){console.error(e)}});async function c(){if(!r()?.name||!r().url&&!r().params)return console.error(`Provider not defined`);if(r().url)n(`oauthFlowRedirectStart`,{provider:r().name}),location.href=r().url;else if(r().params?.client_id&&r().params.redirect_url){if(!r().params.client_id||!r().params.redirect_url)return console.error(`Missing client_id or redirect_url in oauth2ProvidersObj`);let e;switch(r().name){case`google`:e=`https://accounts.google.com/o/oauth2/v2/auth?scope=${r().params.scope}&include_granted_scopes=true&response_type=token&state=state_parameter_passthrough_value&client_id=${r().params.client_id}&redirect_uri=${r().params.redirect_url}`;break;case`github`:e=`https://github.com/login/oauth/authorize?scope=${r().params.scope}&client_id=${r().params.client_id}&redirect_uri=${r().params.redirect_url}`;break;case`gitlab`:e=`https://gitlab.com/oauth/authorize?scope=${r().params.scope}&response_type=code&state=${new Date().valueOf()}&client_id=${r().params.client_id}&redirect_uri=${r().params.redirect_url}`;break;case`facebook`:e=`https://gitlab.com/oauth/authorize?scope=${r().params.scope}&response_type=code&state=${new Date().valueOf()}&client_id=${r().params.client_id}&redirect_uri=${r().params.redirect_url}`;break;case`authentik`:e=`${r().params.auth_server_url}/application/o/authorize/?scope=${r().params.scope}&response_type=code&state=${new Date().valueOf()}&client_id=${r().params.client_id}&redirect_uri=${r().params.redirect_url}`;break;default:return console.error(`no provider uri composed for `+r().name)}if(e)n(`oauthFlowRedirectStart`,{provider:r().name}),location.href=e;else return console.error(`no provider url obtained!?`,r())}else console.warn(`no provider uri or params defined for `+r().name),n(`oauthFlowCustom`,{provider:r().name})}function l(e){i()&&a()&&mr.socialLoginOauthAnswer(e,{authUrl:a(),authCookieName:i()}).then(e=>{console.log(`auth from client`,e),o()?location.href=o():(console.log(`oauthFlowSuccess now`,{token:e}),n(`oauthFlowSuccess`,{token:e}))}).catch(e=>{console.error(`flowerr`,e)})}function u(){if(console.info(`detecting by uri`,location.href),r()?.name){if(r().name===`google`&&location?.href&&location.href.split(`access_token=`).length>1&&location.href.includes(`google`)){console.info(`google auth login detected`);let e=location.href.split(`access_token=`)[1].split(`&`)[0];l({provider:r().name,token:e}),n(`oauthFlowInit`,{provider:r().name,token:e})}if(r().name===`github`&&location?.href&&location.href.includes(`code=`)&&location.href.includes(`provider=`)&&location.href.split(`provider=`)[1].split(`&`)[0]===`github`){console.info(`github auth login detected`);let e=location.href.split(`code=`)[1].split(`&`)[0];l({provider:r().name,token:e,tmpCode:e}),n(`oauthFlowInit`,{provider:r().name,token:e,tmpCode:e})}if(r().name===`facebook`&&location?.href&&location.href.includes(`code=`)&&location.href.includes(`provider=`)&&location.href.split(`provider=`)[1].split(`&`)[0]===`facebook`){console.info(`facebook auth login detected`);let e=location.href.split(`code=`)[1].split(`&`)[0],t=location.href.split(`state=`)[1].split(`&`)[0],i=location.href.replace(`&state=`,``).replace(`?state=`,``).replace(`&code=`,``).replace(`?code=`,``).replace(e,``).replace(t,``);l({provider:r().name,token:e,tmpCode:e,redirect_uri:i}),n(`oauthFlowInit`,{provider:r().name,token:e,tmpCode:e,redirect_uri:i})}if(r().name===`gitlab`&&location?.href&&location.href.includes(`provider=`)&&location.href.includes(`code=`)&&location.href.split(`provider=`)[1].split(`&`)[0]===`gitlab`){let e=location.href.split(`code=`)[1].split(`&`)[0],t=location.href.split(`state=`)[1].split(`&`)[0],i=location.href.replace(`&state=`,``).replace(`?state=`,``).replace(`&code=`,``).replace(`?code=`,``).replace(e,``).replace(t,``);l({provider:r().name,token:e,tmpCode:e,redirect_uri:i}),n(`oauthFlowInit`,{provider:r().name,token:e,tmpCode:e,redirect_uri:location.href.replace(`&state=`,``).replace(`?state=`,``).replace(`&code=`,``).replace(`?code=`,``).replace(e,``).replace(t,``)})}if(r().name===`authentik`&&location?.href&&location.href.includes(`provider=`)&&location.href.includes(`code=`)&&location.href.split(`provider=`)[1].split(`&`)[0]===`authentik`){console.info(`authentik auth login detected`);let e=location.href.split(`code=`)[1].split(`&`)[0],t=location.href.split(`state=`)[1].split(`&`)[0],i=location.href.replace(`&state=`,``).replace(`?state=`,``).replace(`&code=`,``).replace(`?code=`,``).replace(e,``).replace(t,``);l({provider:r().name,token:e,tmpCode:e,redirect_uri:i}),n(`oauthFlowInit`,{provider:r().name,token:e,tmpCode:e,redirect_uri:i})}}}nr(()=>{u()});var d={get provider(){return r()},set provider(e=void 0){r(e),st()},get auth_cookie_name(){return i()},set auth_cookie_name(e=`hb_session`){i(e),st()},get social_auth_server_url(){return a()},set social_auth_server_url(e=void 0){a(e),st()},get redirectonlogin(){return o()},set redirectonlogin(e=void 0){o(e),st()},get id(){return s()},set id(e=``){s(e),st()}},f=br(),p=Vt(f);return ar(Vt(p),t,`default`,{},e=>{var t=Kn(),n=Ht(t),i=e=>{$(e,hr())},a=e=>{$(e,gr())},o=e=>{$(e,_r())},s=e=>{$(e,vr())},c=e=>{$(e,yr())},l=e=>{$(e,Gn(`btn`))};ir(n,e=>{r()?.name===`gitlab`?e(i):r()?.name===`github`?e(a,1):r()?.name===`facebook`?e(o,2):r()?.name===`google`?e(s,3):r()?.name===`authentik`?e(c,4):e(l,-1)}),$(e,t)}),ke(p),ke(f),Fn(`click`,p,()=>{c()}),Fn(`keydown`,p,e=>{(e.key===`Enter`||e.key===` `)&&c()}),$(e,f),ze(d)}In([`click`,`keydown`]),customElements.define(`hb-auth-social-login-button`,pr(Sr,{provider:{},auth_cookie_name:{},social_auth_server_url:{},redirectonlogin:{},id:{}},[`default`],[],{mode:`open`})),e.Component=Sr})(this[`auth-social-login-button`]=this[`auth-social-login-button`]||{});
|
|
43
43
|
//# sourceMappingURL=main.iife.js.map
|