@projectlibertylabs/siwf-sdk-web
v1.0.1
Published
SIWF SDK for Web
Keywords
Readme
Sign-In With Frequency (SIWF) Web Button SDK
🚀 Sign-In With Frequency (SIWF) is an authentication SDK designed for seamless integration with web applications.
This repository contains the SIWF Button Web SDK and example implementation for seamless integration and as a reference for how to use the SIWF Button in your web app.
📌 Index
- 🚀 Getting Started - SIWF Button Demo
- 📝 Getting Started - SIWF Button For Your Web App
- 🛠 Usage For Your Web App
- ⚙️ Configuration Options
- 🤝 Contributing
🚀 Getting Started - SIWF Button Demo
Follow these steps to set up and run the demo:
1️⃣ Clone the Repository
Run the following command in your terminal to clone the repository:
git clone [email protected]:ProjectLibertyLabs/siwf.git
cd siwf/libraries/sdk-web2️⃣ Install Dependencies (if any)
No external dependencies are required! The SDK is designed to be lightweight and dependency-free.
3️⃣ Run the Demo
Start a local server to view the example (for example using npx serve):
npx serve -p 3000 .4️⃣ Open in Browser
Open your browser and navigate to:
http://localhost:3000/example.htmlYour SIWF Button Example should now be running! 🚀
📝 Getting Started - SIWF Button For Your Web App
⚙️ Requirements
The SIWF Button SDK is compatible with all modern browsers:
- Chrome v53+
- Firefox v63+
- Edge v79+
- Safari (macOS) v10+
- Safari (iOS) v11+
- Opera v40+
📥 Installation
Simply include the SDK in your HTML from jsDelivr (update the version as needed):
<script src="https://cdn.jsdelivr.net/npm/@projectlibertylabs/[email protected]/siwf-sdk-web.min.js"></script>Or download from GitHub Releases and include it locally:
<script src="path/to/siwf-sdk-web.min.js"></script>🛠 Usage For Your Web App
When you decide to use the SIWF Button in your own web app, follow the steps below for easy integration:
1️⃣ Define the SIWF Authentication Details
- Refer to the Demo App for examples of encoded signed requests.
- To create your own, use Frequency's Signed Request Generator.
2️⃣ Display the SIWF Sign-In Button
You have two options to add the button to your UI:
Option A: Declarative HTML Implementation
<!-- Add a button container with data attributes -->
<div data-siwf-button="YOUR_ENCODED_SIGNED_REQUEST" data-siwf-mode="primary" data-siwf-endpoint="mainnet"></div>Option B: JavaScript Implementation
<div id="siwf-button-container"></div>
<script>
// Render a button
SiwfButton.render("#siwf-button-container", "YOUR_ENCODED_SIGNED_REQUEST", {
mode: "primary",
endpoint: "mainnet",
});
</script>3️⃣ Handle Authentication Callbacks
Make sure your backend is configured to handle the authentication callback:
- The authentication callback URL must match what was specified in your signed request
- When the authentication flow completes, the user will be redirected to your callback URL
- Your backend should process the authentication response and initiate a session
Resources:
⚙️ Configuration Options
Button Modes
The SIWF Button supports three visual styles:
// Primary mode (teal background, default)
SiwfButton.render("#container", encodedRequest, { mode: "primary" });
// Light mode (white background with border)
SiwfButton.render("#container", encodedRequest, { mode: "light" });
// Dark mode (black background)
SiwfButton.render("#container", encodedRequest, { mode: "dark" });Environments
Choose the authentication environment:
// Production environment
SiwfButton.render("#container", encodedRequest, { endpoint: "mainnet" });
// Testing environment
SiwfButton.render("#container", encodedRequest, { endpoint: "testnet" });
// Custom environment
SiwfButton.render("#container", encodedRequest, { endpoint: "https://custom-mock.example.com" });All Configuration Options
| Option | Type | Default | Description |
| ----------------------------- | ------ | ------------- | ---------------------------------------------------------------------- |
| mode | string | 'primary' | Button style: 'primary', 'light', or 'dark' |
| endpoint | string | 'mainnet' | Authentication environment: 'mainnet', 'testnet', or a custom URL |
| assetsUrl | string | default URL | URL to fetch button assets from |
| additionalCallbackUrlParams | string | '' | Additional parameters to add to the callback URL (query string format) |
Data Attributes
When using HTML declarative implementation, you can configure the button with these attributes:
| Attribute | Description |
| ------------------------------------- | ---------------------------------------------------- |
| data-siwf-button | Required. The encoded signed request |
| data-siwf-mode | Button style (primary, light, or dark) |
| data-siwf-endpoint | Environment (mainnet, testnet, or custom URL) |
| data-siwf-assets-url | Custom assets URL |
| data-additional-callback-url-params | Additional callback parameters (query string format) |
🤝 Contributing
To contribute:
- Fork the repo and create a feature branch.
- Make changes and test.
- Submit a pull request with details.
What's an Encoded Signed Request?
The encoded signed request is a Base64URL-encoded JSON string containing the necessary information for authentication. This includes:
- The public key to verify signatures
- The signature data
- Callback URL
- Requested permissions and credentials
Your application backend or integration partner should provide this encoded signed request.
Security Best Practices
- Always validate authentication responses server-side
- Use HTTPS in production
- Set appropriate Content Security Policy (CSP) headers when deploying
- Never store or expose private keys in client-side code
Developing
Running Tests
This uses visual regression testing. Therefore it is important to run the tests on the correct platform. There are Linux and Docker versions of this test setup:
- Run Visual Regression Tests
- Linux:
npm test - Docker:
npm run test:docker
- Linux:
- Update Visual Regression Snapshots
- Linux:
npm run test:update - Docker:
npm run test:update:docker
- Linux:
Release Process
- Make a new GitHub Release.
- Tag it with the version and the prefix
sdk-web-i.e.sdk-web-v1.0.0. - Complete the release notes.
- CI will run the NPM package release process, tagging it with that version and
latest.
Note: You may also append the -rc<int> (-rc2) suffix to generate a pre-release.
