@yourself_id/siwys-react-js 0.0.27 → 0.0.28-sapp-118-documentation.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 +118 -12
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,19 +1,125 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Sign in with your SELF React SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Sign in with your SELF (SIWYS) is a SELF product that allows users to authenticate with partner apps/dapps using their own private keys and credentials and the MDIP protocol.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This SDK is designed to offer reusable React components to help facilitate the user-facing authentication workflow.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Please refer to the partner integration guide for more information regarding SIWYS.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
2. Run `yarn dev`
|
|
11
|
-
3. Test at http://localhost:5173
|
|
9
|
+
# Install
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
```
|
|
12
|
+
npm install @yourself_id/siwys-react-js
|
|
13
|
+
```
|
|
14
|
+
or
|
|
15
|
+
```
|
|
16
|
+
yarn add @yourself_id/siwys-react-js
|
|
17
|
+
```
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
# Render SIWYS Button
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
```js
|
|
22
|
+
<SiwysButton
|
|
23
|
+
onClick={() => {
|
|
24
|
+
// navigate to dedicated SIWYS page
|
|
25
|
+
}}
|
|
26
|
+
colorTheme="dark"
|
|
27
|
+
glow
|
|
28
|
+
/>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The following are the acceptable props for the `SiwysButton` component:
|
|
32
|
+
|
|
33
|
+
|Parameter|Type|Description|Required|Default|
|
|
34
|
+
|--|-|-|-|-|
|
|
35
|
+
|onClick|func|Function to execute.<br/>This should redirect to a dedicated page that renders the `SignInWithYourSelf` Component (below) |Yes||
|
|
36
|
+
|colorTheme|string|Color theme of button. <br/>Either "light" or "dark"|No|Auto-detect from system|
|
|
37
|
+
|glow|boolean|Whether to show glow hover effect|No|false|
|
|
38
|
+
|
|
39
|
+
# Render SIWYS Component
|
|
40
|
+
|
|
41
|
+
The SIWYS component includes the QR code for scanning as well as additional information to inform users on how to take action. Consequently, this component should ideally be rendered on its own dedicated page to avoid any formatting/styling issues.
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
<SignInWithYourSelf
|
|
45
|
+
createChallengeUrl="https://your-sever-url/challenges"
|
|
46
|
+
pollForChallengeComplete="https://your-server-url/auth"
|
|
47
|
+
pollingIntervalSec={5}
|
|
48
|
+
onChallengeComplete={(resp) => console.log("Auth Respone:", resp)}
|
|
49
|
+
/>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The following are the acceptable props for the `SignInWithYourSelf` component:
|
|
53
|
+
|
|
54
|
+
|Parameter|Type|Description|Required|Default|
|
|
55
|
+
|--|-|-|-|-|
|
|
56
|
+
|createChallengeUrl|func|URL for creating the Challenge.<br/>This should be the endpoint you created when setting up the SIWYS API SDK.|Yes||
|
|
57
|
+
|pollForChallengeComplete|string|URL polling for challenge completion status.<br/>This should be the endpoint you created when setting up the SIWYS API SDK.|No|The component will not poll for challenge completion.|
|
|
58
|
+
|pollingIntervalSec|boolean|How often to poll for Challenge completion.|No|5|
|
|
59
|
+
|onChallengeComplete|boolean|Callback for handling a completed Challenge.<br/>Will pass back the result of the polling endpoint.<br/>Required when `pollForAuthUrl` is supplied.|No|N/A|
|
|
60
|
+
|
|
61
|
+
> [!IMPORTANT]
|
|
62
|
+
> If you do not provide the `pollForAuthUrl` you must implement your own logic of informing the Client when the challenge has been completed.
|
|
63
|
+
> For more information see the setup guide for the SIWYS API SDK.
|
|
64
|
+
|
|
65
|
+
# Complete Example
|
|
66
|
+
|
|
67
|
+
The following is a complete, minimal example using Next.js and assuming that the `pollForChallengeCompleteUrl` sets the appropriate authentication mechansim, eg a JWT cookie.
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
// index.tsx entrypoint
|
|
71
|
+
import React, { render, useEffect, useState } from "react"
|
|
72
|
+
|
|
73
|
+
import { useRouter } from 'next/router';
|
|
74
|
+
|
|
75
|
+
import { SiwysButton } from "@yourself_id/react-js";
|
|
76
|
+
|
|
77
|
+
const App: React.FC<{}> = () => {
|
|
78
|
+
const [user, setUser] = useState();
|
|
79
|
+
|
|
80
|
+
const router = useRouter();
|
|
81
|
+
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
// fetch user info if authenticated
|
|
84
|
+
fetch("/me").then(setUser)
|
|
85
|
+
}, [])
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<div>
|
|
89
|
+
{user && <Homepage />}
|
|
90
|
+
{!user && (
|
|
91
|
+
<SiwysButton
|
|
92
|
+
colorTheme="dark"
|
|
93
|
+
glow
|
|
94
|
+
onClick={() => router.push("/login")}
|
|
95
|
+
/>
|
|
96
|
+
)}
|
|
97
|
+
</div>
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export default App;
|
|
102
|
+
|
|
103
|
+
render(<App />, document.getElementById('app')!)
|
|
104
|
+
|
|
105
|
+
// pages/login/index.tsx
|
|
106
|
+
import React, { render, useState } from "react"
|
|
107
|
+
|
|
108
|
+
import { SignInWithYourSelf } from "@yourself_id/react-js";
|
|
109
|
+
|
|
110
|
+
const Login: React.FC<{}> = () => {
|
|
111
|
+
const router = useRouter();
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<SignInWithYourSelf
|
|
115
|
+
createChallengeUrl="https://your-server-url/challenges"
|
|
116
|
+
pollForChallengeCompleteUrl="https://your-server-url/auth"
|
|
117
|
+
onChallengeComplete={() => router.push("/")}
|
|
118
|
+
/>
|
|
119
|
+
);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export default Login;
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Note: `onChallengeComplete` may have a Coo
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yourself_id/siwys-react-js",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.28-sapp-118-documentation.0+c67697f",
|
|
4
4
|
"description": "A React component library",
|
|
5
5
|
"repository": "https://github.com/selfidhq/siwys-js",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"resolutions": {
|
|
51
51
|
"styled-components": "^6"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "c67697fc65379095623304473e512803079cb7ee"
|
|
54
54
|
}
|