With Logaflow’s SSO Auth Token, you can authenticate your users logged into your application to identify them on the Logaflow dashboard.
This step is optional, but we recommend implementing it to better manage each user’s feedback. Since they are already authenticated, users with SSO Token will not see the Name and Email fields when opening the Logaflow widget.
using System;using System.IdentityModel.Tokens.Jwt;using System.Security.Claims;using Microsoft.IdentityModel.Tokens;using System.Text;class User{ public string Name { get; set; } public string Email { get; set; } public string Avatar { get; set; } public string Id { get; set; } public User(string name, string email, string avatar = null, string id = null) { Name = name; Email = email; Avatar = avatar; Id = id; }}class Program{ private const string LOGAFLOW_PROJECT_SECRET = "YOUR_LOGAFLOW_PROJECT_SSO_SECRET"; static string GenerateLogaflowUserSSOToken(User user) { var claims = new[] { new Claim("id", user.Id ?? ""), // optional new Claim("name", user.Name), // required new Claim("email", user.Email), // required new Claim("avatar", user.Avatar ?? "") // optional }; var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(LOGAFLOW_PROJECT_SECRET)); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var token = new JwtSecurityToken( claims: claims, signingCredentials: creds ); return new JwtSecurityTokenHandler().WriteToken(token); }}
2
Authenticate your user in the Widget
To authenticate your user in the widget, you need to pass the generated token to the Logaflow widget:
<!DOCTYPE html><html lang="en"><head> ... <!-- Logaflow widget script --> <script type="module" crossorigin="true" async src="https://widget.logaflow.com/addons/logaflow-widget.umd.js?version=1.0.3" ></script></head><body> <!-- Add Logaflow widget web component to the top of your --> <logaflow-widget project-key="YOUR_LOGAFLOW_PROJECT_TOKEN_HERE" trigger-text="Example" sso-token="USER_SSO_TOKEN" <!-- Pass user SSO Token here --> ></logaflow-widget> ...</body></html>
import React from 'react'import ReactDOM from 'react-dom/client'import { LogaflowWidget, useLogaflowSSOAuth } from '@logaflow/react'import '@/styles/globals.css'ReactDOM.createRoot(document.getElementById('root')!).render( <React.StrictMode> <> {/* Add the logaflow widget to the top of your react project */} <LogaflowWidget projectKey={YOUR_PROJECT_TOKEN} /> <YourApp /> </> </React.StrictMode>)function YourApp() { const { setSSOAuth } = useLogaflowSSOAuth() useEffect(() => { // ... your rule to get user sso token setSSOAuth(token) }, [setSSOAuth]) ...}
// components/logaflow-sso-auth.tsx"use client"import { useLogaflowSSOAuth } from '@logaflow/next'export function LogaflowSSOAuth() { const { setSSOAuth } = useLogaflowSSOAuth() useEffect(() => { // ... your rule to get user sso token setSSOAuth(token) }, [])}// import and add the LogaflowSSOAuth component in any location after the LogaflowWidget setup component
3
All set!
After these steps, your user will be authenticated and you will be able to identify them in the feedback sent by them on the feedback details page: