@canicula/sirius-oidc-client 0.0.0-stage → 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 +45 -2
- package/dist/index.d.ts +14 -0
- package/dist/index.js +61 -0
- package/dist/style.css +23 -0
- package/package.json +27 -4
package/README.md
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @canicula/sirius-oidc-client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Boutons **Se connecter avec Sirius** / **Se déconnecter** pour un outil interne.
|
|
4
|
+
|
|
5
|
+
À utiliser avec [`@canicula/sirius-oidc-server`](https://www.npmjs.com/package/@canicula/sirius-oidc-server)
|
|
6
|
+
côté backend (routes `/login`, `/auth/callback`, `/logout` et lecture de
|
|
7
|
+
session).
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @canicula/sirius-oidc-client
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Le profil (`name`, `email`, etc.) s’affiche dans **votre** UI, pas dans ces
|
|
14
|
+
boutons.
|
|
15
|
+
|
|
16
|
+
## HTML
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import "@canicula/sirius-oidc-client/style.css";
|
|
20
|
+
import { signInHtml, signOutHtml } from "@canicula/sirius-oidc-client";
|
|
21
|
+
|
|
22
|
+
page.innerHTML = session ? signOutHtml() : signInHtml();
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Par défaut : connexion → `/login`, déconnexion → `/logout`.
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
signInHtml({ href: "/auth/login", label: "Connexion Sirius" });
|
|
29
|
+
signOutHtml({ href: "/auth/logout", label: "Quitter" });
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Custom elements
|
|
33
|
+
|
|
34
|
+
Importer le module enregistre `sirius-sign-in` et `sirius-sign-out` :
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import "@canicula/sirius-oidc-client";
|
|
38
|
+
import "@canicula/sirius-oidc-client/style.css";
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```html
|
|
42
|
+
<sirius-sign-in></sirius-sign-in>
|
|
43
|
+
<sirius-sign-out href="/logout" label="Se déconnecter"></sirius-sign-out>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Attributs optionnels : `href`, `label`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare function escapeHtml(value: string): string;
|
|
2
|
+
declare function signInHtml({ href, label, }?: {
|
|
3
|
+
href?: string | undefined;
|
|
4
|
+
label?: string | undefined;
|
|
5
|
+
}): string;
|
|
6
|
+
declare function signOutHtml({ href, label, }?: {
|
|
7
|
+
href?: string | undefined;
|
|
8
|
+
label?: string | undefined;
|
|
9
|
+
}): string;
|
|
10
|
+
declare function mountHtml(element: ParentNode, html: string): void;
|
|
11
|
+
|
|
12
|
+
declare function registerSiriusOidcElements(): void;
|
|
13
|
+
|
|
14
|
+
export { escapeHtml, mountHtml, registerSiriusOidcElements, signInHtml, signOutHtml };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/html.ts
|
|
2
|
+
function escapeHtml(value) {
|
|
3
|
+
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """);
|
|
4
|
+
}
|
|
5
|
+
function signInHtml({
|
|
6
|
+
href = "/login",
|
|
7
|
+
label = "Se connecter avec Sirius"
|
|
8
|
+
} = {}) {
|
|
9
|
+
return `<a class="sirius-oidc-button sirius-oidc-button--primary" href="${escapeHtml(href)}">${escapeHtml(label)}</a>`;
|
|
10
|
+
}
|
|
11
|
+
function signOutHtml({
|
|
12
|
+
href = "/logout",
|
|
13
|
+
label = "Se d\xE9connecter"
|
|
14
|
+
} = {}) {
|
|
15
|
+
return `<a class="sirius-oidc-button sirius-oidc-button--ghost" href="${escapeHtml(href)}">${escapeHtml(label)}</a>`;
|
|
16
|
+
}
|
|
17
|
+
function mountHtml(element, html) {
|
|
18
|
+
if ("innerHTML" in element) {
|
|
19
|
+
element.innerHTML = html;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/elements.ts
|
|
24
|
+
function define(name, ctor) {
|
|
25
|
+
if (typeof customElements === "undefined") return;
|
|
26
|
+
if (!customElements.get(name)) customElements.define(name, ctor);
|
|
27
|
+
}
|
|
28
|
+
function registerSiriusOidcElements() {
|
|
29
|
+
define(
|
|
30
|
+
"sirius-sign-in",
|
|
31
|
+
class extends HTMLElement {
|
|
32
|
+
connectedCallback() {
|
|
33
|
+
this.innerHTML = signInHtml({
|
|
34
|
+
href: this.getAttribute("href") ?? "/login",
|
|
35
|
+
label: this.getAttribute("label") ?? "Se connecter avec Sirius"
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
define(
|
|
41
|
+
"sirius-sign-out",
|
|
42
|
+
class extends HTMLElement {
|
|
43
|
+
connectedCallback() {
|
|
44
|
+
this.innerHTML = signOutHtml({
|
|
45
|
+
href: this.getAttribute("href") ?? "/logout",
|
|
46
|
+
label: this.getAttribute("label") ?? "Se d\xE9connecter"
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
if (typeof window !== "undefined") {
|
|
53
|
+
registerSiriusOidcElements();
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
escapeHtml,
|
|
57
|
+
mountHtml,
|
|
58
|
+
registerSiriusOidcElements,
|
|
59
|
+
signInHtml,
|
|
60
|
+
signOutHtml
|
|
61
|
+
};
|
package/dist/style.css
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
.sirius-oidc-button {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
font: 600 16px/1.2 system-ui, sans-serif;
|
|
5
|
+
text-decoration: none;
|
|
6
|
+
border-radius: 999px;
|
|
7
|
+
padding: 12px 20px;
|
|
8
|
+
border: 1px solid transparent;
|
|
9
|
+
cursor: pointer;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.sirius-oidc-button--primary {
|
|
13
|
+
background: #18181b;
|
|
14
|
+
color: #fff;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.sirius-oidc-button--ghost {
|
|
18
|
+
background: #fff;
|
|
19
|
+
color: #27272a;
|
|
20
|
+
border-color: #d4d4d8;
|
|
21
|
+
padding: 8px 16px;
|
|
22
|
+
font-weight: 500;
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canicula/sirius-oidc-client",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Boutons Se connecter / Se déconnecter avec Sirius.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./style.css": "./dist/style.css",
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"files": ["dist"],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup src/index.ts --format esm --dts --clean && cp src/style.css dist/style.css",
|
|
23
|
+
"prepare": "npm run build"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"tsup": "^8.5.1",
|
|
27
|
+
"typescript": "^5.9.3"
|
|
28
|
+
}
|
|
29
|
+
}
|