Skip to content

WeAreFlowsta/flowsta-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

22 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Flowsta SDK

Official JavaScript SDK for Flowsta Authentication - Zero-knowledge, OAuth-based Single Sign-On for web applications.

npm version License: MIT

New to Flowsta? Create a developer account to get your Client ID.

πŸ“¦ Packages

Package Version Description
@flowsta/auth ⭐ 2.0.0 Core OAuth SDK with React bindings
@flowsta/login-button 0.1.0 Pre-built button components
@flowsta/holochain 1.0.0 Holochain integration

πŸš€ Getting Started

Prerequisites

  1. Get your Client ID: Sign up at dev.flowsta.com
  2. Add redirect URI: Configure https://yoursite.com/auth/callback in your app settings

Choose Your Integration Method

Option 1: NPM Package (Recommended)

Install the SDK for modern web apps:

npm install @flowsta/auth

Option 2: Pre-built Buttons

For quick integration with UI components:

npm install @flowsta/login-button

Supports: React, Vue, Qwik, Vanilla JS

Option 3: No Build Tools?

Use vanilla JavaScript without npm:

Core SDK Features

OAuth 2.0 authentication with PKCE - no client secrets needed.

Features:

  • βœ… OAuth 2.0 + PKCE (Proof Key for Code Exchange)
  • βœ… Zero-knowledge architecture - user data stays encrypted
  • βœ… React bindings included (@flowsta/auth/react)
  • βœ… TypeScript-first with full type safety
  • βœ… Zero dependencies - lightweight (< 10kb)
  • βœ… Works in any JavaScript environment

Pre-built "Sign in with Flowsta" button components.

Features:

  • βœ… Multiple frameworks: React, Vue, Qwik, Vanilla JS
  • βœ… 6 button variants (dark/light/neutral Γ— pill/rectangle)
  • βœ… Automatic PKCE generation and state management
  • βœ… Customizable styling and behavior
  • βœ… Inline SVG assets - works with any bundler

Sign Holochain actions using your Flowsta identity.

Features:

  • βœ… Sign zome calls with Flowsta agent key
  • βœ… Seamless Holochain integration
  • βœ… TypeScript support

πŸ’‘ Quick Start Examples

Vanilla JavaScript (No Build Tools)

Perfect for static HTML sites or simple projects:

<!DOCTYPE html>
<html>
<head>
  <title>Login with Flowsta</title>
</head>
<body>
  <a href="#" id="login-btn">
    <img src="https://docs.flowsta.com/buttons/svg/flowsta_signin_web_dark_pill.svg" 
         alt="Sign in with Flowsta" 
         width="175" height="40">
  </a>

  <script type="module">
    import { FlowstaAuth } from 'https://unpkg.com/@flowsta/auth';

    const auth = new FlowstaAuth({
      clientId: 'your-client-id',
      redirectUri: window.location.origin + '/callback.html'
    });

    document.getElementById('login-btn').addEventListener('click', (e) => {
      e.preventDefault();
      auth.login();
    });
  </script>
</body>
</html>

View Complete Vanilla JS Guide β†’

React with Hooks

Using the built-in React bindings:

import { FlowstaAuthProvider, useFlowstaAuth } from '@flowsta/auth/react';
import { FlowstaLoginButton } from '@flowsta/login-button/react';

function App() {
  return (
    <FlowstaAuthProvider
      clientId="your-client-id"
      redirectUri="https://yoursite.com/auth/callback"
    >
      <Dashboard />
    </FlowstaAuthProvider>
  );
}

function Dashboard() {
  const { isAuthenticated, user, login, logout } = useFlowstaAuth();
  
  if (!isAuthenticated) {
    return <FlowstaLoginButton onClick={login} variant="dark-pill" />;
  }
  
  return (
    <div>
      <h1>Welcome, {user?.displayName}!</h1>
      <p>@{user?.username}</p>
      <button onClick={logout}>Logout</button>
    </div>
  );
}

Vue 3 with Composition API

<script setup>
import { FlowstaAuth } from '@flowsta/auth';
import { FlowstaLoginButtonVue } from '@flowsta/login-button/vue';
import { ref, onMounted } from 'vue';

const auth = new FlowstaAuth({
  clientId: 'your-client-id',
  redirectUri: 'https://yoursite.com/callback'
});

const user = ref(null);
const isAuthenticated = ref(false);

onMounted(() => {
  isAuthenticated.value = auth.isAuthenticated();
  user.value = auth.getUser();
});

const login = () => auth.login();
const logout = () => {
  auth.logout();
  isAuthenticated.value = false;
  user.value = null;
};
</script>

<template>
  <div v-if="!isAuthenticated">
    <FlowstaLoginButtonVue
      client-id="your-client-id"
      redirect-uri="https://yoursite.com/callback"
      variant="dark-pill"
    />
  </div>
  <div v-else>
    <h1>Welcome, {{ user?.displayName }}!</h1>
    <button @click="logout">Logout</button>
  </div>
</template>

Core SDK (TypeScript)

For maximum control and flexibility:

import { FlowstaAuth } from '@flowsta/auth';

const auth = new FlowstaAuth({
  clientId: 'your-client-id',
  redirectUri: 'https://yoursite.com/auth/callback',
  scopes: ['openid', 'email', 'display_name', 'username']
});

// Redirect to Flowsta login
auth.login();

// On your callback page
try {
  const user = await auth.handleCallback();
  console.log('Authenticated:', user.displayName, user.username);
  // Redirect to dashboard
  window.location.href = '/dashboard';
} catch (error) {
  console.error('Authentication failed:', error);
  window.location.href = '/login?error=auth_failed';
}

🎨 Button Variants

The @flowsta/login-button package includes 6 official button styles:

Variant Best For Preview
dark-pill Light backgrounds (recommended) Dark Pill
dark-rectangle Light backgrounds, square style Dark Rectangle
light-pill Dark backgrounds Light Pill
light-rectangle Dark backgrounds, square style Light Rectangle
neutral-pill Any background Neutral Pill
neutral-rectangle Any background, square style Neutral Rectangle

Download all button assets β†’

πŸ‘€ User Data & Scopes

After authentication, you'll receive a FlowstaUser object with the requested scopes:

interface FlowstaUser {
  sub: string;              // Unique user ID (always available)
  display_name?: string;    // Display name (if 'display_name' scope)
  username?: string;        // Username (if 'username' scope)
  email?: string;           // Email (if 'email' scope)
  email_verified?: boolean; // Email verification status
  profile_picture?: string; // Profile picture URL (if 'profile_picture' scope)
  agent_pub_key?: string;   // Holochain agent key (if 'public_key' scope)
  did?: string;             // Decentralized ID (if 'did' scope)
}

Available Scopes:

  • openid - Required, provides user ID
  • email - User's email address
  • display_name - User's display name
  • username - User's @username
  • profile_picture - Profile picture URL
  • public_key - Holochain agent public key
  • did - W3C Decentralized Identifier

πŸ” What is Flowsta?

Flowsta provides zero-knowledge authentication powered by Holochain:

  • πŸ” Zero-Knowledge: Your data is encrypted end-to-end - only you can decrypt it
  • 🌐 Single Sign-On: One login works across all Flowsta-enabled applications
  • πŸ”‘ Decentralized Identity: Built on Holochain's DHT for censorship resistance
  • ⚑ Easy Integration: Standard OAuth 2.0 with PKCE security
  • πŸ›‘οΈ Privacy-First: No tracking, no data mining, no selling your information

How It Works

  1. User logs in via login.flowsta.com
  2. Data is encrypted with user's password (zero-knowledge)
  3. Stored on Holochain DHT (decentralized, censorship-resistant)
  4. Your app receives an access token via OAuth
  5. Fetch user data from the Auth API (decrypted on-demand)

πŸ“š Documentation

Official Docs

Package READMEs

Developer Resources

πŸ—‘οΈ Deprecated Packages (SDK 1.0)

The following packages are from SDK 1.0 and should not be used for new projects:

Package Status Replacement
@flowsta/auth-sdk ⚠️ Deprecated Use @flowsta/auth (v2.0)
@flowsta/auth-client ⚠️ Deprecated Use @flowsta/auth (v2.0)
@flowsta/auth-react ⚠️ Deprecated Use @flowsta/auth/react
@flowsta/auth-widgets ⚠️ Deprecated Not needed (OAuth-only in v2.0)

Why the migration? SDK 2.0 uses OAuth-only authentication for better security and simpler integration. No more email/password handling in your app!

πŸ› οΈ Development

Setup

# Clone the repository
git clone https://github.com/WeAreFlowsta/flowsta-sdk.git
cd flowsta-sdk

# Install dependencies
npm install

# Build all packages
npm run build

Available Scripts

npm run build       # Build all packages
npm run dev         # Watch mode for development
npm run test        # Run tests (coming soon)
npm run lint        # Lint code (coming soon)

Package Structure

sdk-monorepo/
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ auth/              # Core OAuth SDK (v2.0)
β”‚   β”œβ”€β”€ login-button/      # Pre-built button components
β”‚   β”œβ”€β”€ holochain/         # Holochain signing integration
β”‚   β”œβ”€β”€ core/              # [Deprecated] SDK 1.0 core
β”‚   β”œβ”€β”€ client/            # [Deprecated] SDK 1.0 client
β”‚   β”œβ”€β”€ react/             # [Deprecated] SDK 1.0 React
β”‚   └── widgets/           # [Deprecated] SDK 1.0 widgets
└── README.md

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

πŸ“„ License

MIT Β© Flowsta

πŸ”— Links


Questions? Join our Discord community or check out the documentation.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published