### Basic Echo Server Setup Source: https://docs.logto.io/api-protection/go/echo Create a minimal Echo server in Go. This code initializes the Echo instance and starts the server on port 3000. Ensure you have the Echo framework installed. ```go package main import ( "github.com/labstack/echo/v4" ) func main() { e := echo.New() e.Logger.Fatal(e.Start(":3000")) } ``` -------------------------------- ### Initialize Laravel Project with Installer Source: https://docs.logto.io/api-protection/php/laravel Use the Laravel installer for a quick project setup. Ensure you have Composer installed globally. ```bash composer global require laravel/installer laravel new your-api-name cd your-api-name ``` -------------------------------- ### Initialize Go Project with Gin Source: https://docs.logto.io/api-protection/go/gin Use `go mod init` and `go get` to set up a new Go project and install the Gin framework. ```bash go mod init your-api-name go get github.com/gin-gonic/gin ``` -------------------------------- ### Silent Logto Installation Example (CLI) Source: https://docs.logto.io/logto-oss/using-cli/install-logto Perform a silent Logto installation using CLI arguments, suitable for CI environments. This example initializes Logto in a specified path, configures the database, and adds official connectors. ```bash logto init -p ./logto --db-url postgresql://your-postgres-dsn:5432/logto --oc ``` -------------------------------- ### Initialize Go Project with Chi Source: https://docs.logto.io/api-protection/go/chi Use `go mod init` and `go get` to set up a new Go project and install the Chi router. This is the first step for building an API with Chi. ```bash go mod init your-api-name go get github.com/go-chi/chi/v5 ``` -------------------------------- ### Initialize Go Project with Echo Source: https://docs.logto.io/api-protection/go/echo Use `go mod init` to create a new Go module and `go get` to install the Echo framework. This sets up the basic project structure for your API. ```bash go mod init your-api-name go get github.com/labstack/echo/v4 ``` -------------------------------- ### Basic Slim Application Setup Source: https://docs.logto.io/api-protection/php/slim Create a basic Slim application with a root route that returns a JSON message. Ensure you have the Slim Framework and PSR-7 dependencies installed. ```php addErrorMiddleware(true, true, true); // Basic route $app->get('/', function (Request $request, Response $response) { $response->getBody()->write(json_encode(['message' => 'Hello from Slim API'])); return $response->withHeader('Content-Type', 'application/json'); }); $app->run(); ``` -------------------------------- ### Basic NestJS Server Setup (main.ts) Source: https://docs.logto.io/api-protection/nodejs/nestjs Sets up the NestJS application instance and starts the HTTP server. This file is the entry point for your NestJS application. ```typescript import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); await app.listen(3000); console.log('Server running on http://localhost:3000'); } bootstrap(); ``` -------------------------------- ### Silent Logto Installation Example (npm) Source: https://docs.logto.io/logto-oss/using-cli/install-logto Perform a silent Logto installation using npx and npm arguments, suitable for CI environments. This example initializes Logto in a specified path, configures the database, and adds official connectors. ```bash npx @logto/cli init -p ./logto --db-url postgresql://your-postgres-dsn:5432/logto --oc ``` -------------------------------- ### Basic Axum Application Setup Source: https://docs.logto.io/api-protection/rust/axum Sets up a basic Axum application with a single GET route for the root path, returning a JSON response. ```rust use axum::{ response::Json, routing::get, Router, }; use serde_json::{json, Value}; #[tokio::main] async fn main() { let app = Router::new() .route("/", get(hello_handler)); let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); axum::serve(listener, app).await.unwrap(); } async fn hello_handler() -> Json { Json(json!({ "message": "Hello from Axum" })) } ``` -------------------------------- ### Basic Vert.x Web Server Implementation Source: https://docs.logto.io/api-protection/java/vertx-web Create a simple Vert.x Web server that listens on port 3000 and responds to GET requests at the /hello endpoint. This example includes basic routing and response handling. ```java package com.example; import io.vertx.core.AbstractVerticle; import io.vertx.core.Promise; import io.vertx.ext.web.Router; import io.vertx.ext.web.handler.BodyHandler; public class MainVerticle extends AbstractVerticle { @Override public void start(Promise startPromise) throws Exception { Router router = Router.router(vertx); router.route().handler(BodyHandler.create()); router.get("/hello").handler(ctx -> { ctx.response() .putHeader("content-type", "text/plain") .end("Hello from Vert.x Web!"); }); vertx.createHttpServer() .requestHandler(router) .listen(3000, http -> { if (http.succeeded()) { startPromise.complete(); System.out.println("HTTP server started on port 3000"); } else { startPromise.fail(http.cause()); } }); } } ``` -------------------------------- ### Install Auth.js Source: https://docs.logto.io/quick-starts/next-auth Install the Auth.js package using npm, pnpm, or yarn. ```bash npm i next-auth@beta ``` ```bash pnpm add next-auth@beta ``` ```bash yarn add next-auth@beta ``` -------------------------------- ### Install @logto/browser with npm Source: https://docs.logto.io/quick-starts/vanilla-js Use npm to install the Logto Browser SDK. Ensure you have Node.js and npm installed. ```bash npm i @logto/browser ``` -------------------------------- ### Install jwx Dependency Source: https://docs.logto.io/api-protection/go/echo Initialize your Go module and install the jwx library for JWT handling. ```bash go mod init your-project go get github.com/lestrrat-go/jwx/v3 ``` -------------------------------- ### Install Django Source: https://docs.logto.io/api-protection/python/django Install the Django framework using pip if it's not already present on your system. ```bash pip install Django ``` -------------------------------- ### Install Logto SDK with pnpm Source: https://docs.logto.io/quick-starts/sveltekit Install the Logto SDK for SvelteKit using pnpm. ```bash pnpm add @logto/sveltekit ``` -------------------------------- ### Interactive Logto Installation (npm) Source: https://docs.logto.io/logto-oss/using-cli/install-logto Use this npm command for an interactive Logto installation. ```bash npm init @logto@latest ``` -------------------------------- ### Install Logto SDK with npm Source: https://docs.logto.io/quick-starts/passport Install the necessary packages for Passport.js and OpenID Connect strategy using npm. ```bash npm i passport passport-openidconnect ``` -------------------------------- ### Install Logto React SDK Source: https://docs.logto.io/quick-starts/react Install the Logto SDK for React using npm, pnpm, or yarn. ```bash npm i @logto/react ``` ```bash pnpm add @logto/react ``` ```bash yarn add @logto/react ``` -------------------------------- ### Logto Installation Options Source: https://docs.logto.io/logto-oss/using-cli/install-logto These options can be added to `logto init` to skip interactive questions during installation. Use `logto init --help` for a full list. ```bash # All these options are optional --db-url The Postgres URL to Logto database -p, --path Path to your Logto instance, must be a non-existing path --ss Skip Logto database seeding --oc Add official connectors after installation ``` -------------------------------- ### Initialize Go Fiber Project Source: https://docs.logto.io/api-protection/go/fiber Use `go mod init` and `go get` to set up a new Go project with the Fiber framework. ```bash go mod init your-api-name go get github.com/gofiber/fiber/v2 ``` -------------------------------- ### Basic Flask Application Setup Source: https://docs.logto.io/api-protection/python/flask Create a simple Flask application with a root route that returns a JSON message. This serves as a basic starting point for your API. ```python from flask import Flask, jsonify app = Flask(__name__) @app.route('/') def hello(): return jsonify({"message": "Hello from Flask"}) if __name__ == '__main__': app.run(debug=True) ``` -------------------------------- ### Basic Fiber Server Setup Source: https://docs.logto.io/api-protection/go/fiber Create a minimal Fiber application that listens on port 3000. Ensure you have the necessary imports. ```go package main import ( "log" "github.com/gofiber/fiber/v2" ) func main() { app := fiber.New() log.Fatal(app.Listen(":3000")) } ``` -------------------------------- ### Implement Sign-In and Sign-Out Buttons Source: https://docs.logto.io/quick-starts/vue Use the `useLogto` composable to get `signIn`, `signOut`, and `isAuthenticated` functions. This example shows how to conditionally render Sign In or Sign Out buttons based on authentication status. ```typescript import { useLogto } from '@logto/vue'; const { signIn, signOut, isAuthenticated } = useLogto(); const onClickSignIn = () => signIn('http://localhost:3000/callback'); const onClickSignOut = () => signOut('http://localhost:3000'); ``` -------------------------------- ### Start Development Server Source: https://docs.logto.io/api-protection/php/slim Run a local development server for your Slim API, serving files from the public directory. ```bash php -S localhost:8000 -t public/ ``` -------------------------------- ### Fetch Logto Applications using Access Token Source: https://docs.logto.io/integrate-logto/interact-with-management-api Example of fetching Logto applications using a Bearer token. This demonstrates how to make a GET request to the `/api/applications` endpoint with the appropriate Authorization header. ```javascript const logtoEndpoint = 'https://your.logto.endpoint'; // Replace with your Logto endpoint const accessToken = 'eyJhb...2g'; // Access Token const fetchLogtoApplications = async () => { return await fetch(`${logtoEndpoint}/api/applications`, { method: 'GET', headers: { Authorization: `Bearer ${accessToken}`, }, }); }; ``` -------------------------------- ### Initialize Slim Project with Composer Source: https://docs.logto.io/api-protection/php/slim Use Composer to create a new Slim project structure and install necessary dependencies. ```bash mkdir your-api-name cd your-api-name composer init ``` ```bash composer require slim/slim:"4.*" composer require slim/psr7 composer require slim/http ``` ```bash mkdir -p public src/Middleware src/Controllers ``` -------------------------------- ### Build Logto Experience Project Source: https://docs.logto.io/customization/bring-your-ui Run this command to build the Logto Sign-in Experience UI project after cloning it. Ensure you have pnpm installed. ```bash pnpm install && pnpm build ``` -------------------------------- ### Clone and run MCP Inspector Source: https://docs.logto.io/use-cases/ai/mcp-server-add-auth This command sequence clones the mcp-auth inspector repository, installs its dependencies, and starts the development server. This inspector is used to test the integration with the "whoami" tool. ```bash git clone https://github.com/mcp-auth/inspector.git cd inspector npm install npm run dev ``` -------------------------------- ### Initialize .NET Web API Project Source: https://docs.logto.io/api-protection/dotnet/aspnet-core Use the .NET CLI to create a new Web API project and navigate into its directory. This is the first step for setting up your API. ```bash dotnet new webapi -n YourApiName cd YourApiName ``` -------------------------------- ### Basic Fastify Server Setup Source: https://docs.logto.io/api-protection/nodejs/fastify Create a basic Fastify server instance that listens on port 3000. Ensure proper error handling for the server startup. ```typescript import fastify from 'fastify'; const server = fastify({ logger: true }); try { await server.listen({ port: 3000 }); console.log('Server running on http://localhost:3000'); } catch (err) { server.log.error(err); process.exit(1); } ``` -------------------------------- ### Install @logto/browser with yarn Source: https://docs.logto.io/quick-starts/vanilla-js Use yarn to install the Logto Browser SDK. Ensure you have yarn installed. ```bash yarn add @logto/browser ``` -------------------------------- ### Install @logto/browser with pnpm Source: https://docs.logto.io/quick-starts/vanilla-js Use pnpm to install the Logto Browser SDK. Ensure you have pnpm installed. ```bash pnpm add @logto/browser ``` -------------------------------- ### Start Development Server Source: https://docs.logto.io/api-protection/dotnet/aspnet-core Run the .NET development server to host your Web API. This command starts the application for local testing. ```bash dotnet run ``` -------------------------------- ### Install Logto Nuxt SDK using Yarn Source: https://docs.logto.io/quick-starts/nuxt Install the Logto Nuxt SDK using Yarn. Ensure you have Node.js and Yarn installed. ```bash yarn add @logto/nuxt ``` -------------------------------- ### Install Logto Go SDK Packages Source: https://docs.logto.io/quick-starts/go Execute these commands in your project root to install the core and client packages for the Logto Go SDK. ```bash # Install the core package for accessing predefined values and types go get github.com/logto-io/go/v2/core # Install the client package for interacting with the Logto go get github.com/logto-io/go/v2/client ``` -------------------------------- ### Install Logto Nuxt SDK using pnpm Source: https://docs.logto.io/quick-starts/nuxt Install the Logto Nuxt SDK using pnpm. Ensure you have Node.js and pnpm installed. ```bash pnpm add @logto/nuxt ``` -------------------------------- ### Basic Hapi Server Setup Source: https://docs.logto.io/api-protection/nodejs/hapi Create a basic Hapi server instance. Refer to Hapi documentation for advanced configurations like routes and plugins. ```typescript import Hapi from '@hapi/hapi'; const server = Hapi.server({ port: 3000, host: 'localhost', }); await server.start(); console.log('Server running on http://localhost:3000'); ``` -------------------------------- ### Install Logto Nuxt SDK using npm Source: https://docs.logto.io/quick-starts/nuxt Install the Logto Nuxt SDK using npm. Ensure you have Node.js and npm installed. ```bash npm i @logto/nuxt ``` -------------------------------- ### Basic Gin Server Setup Source: https://docs.logto.io/api-protection/go/gin Create a basic Gin server that listens on port 3000. This serves as the foundation for your API. ```go package main import ( "github.com/gin-gonic/gin" ) func main() { r := gin.Default() r.Run(":3000") // listen and serve on 0.0.0.0:3000 } ``` -------------------------------- ### Install PyJWT Source: https://docs.logto.io/api-protection/python/flask Install the PyJWT library with cryptographic support. ```bash pip install pyjwt[crypto] ``` -------------------------------- ### Implement Logto Sign-In Route and Link Source: https://docs.logto.io/quick-starts/go This Go code snippet demonstrates how to implement a '/sign-in' route to initiate the Logto sign-in process. It also shows how to add a 'Sign In' link to the home page. The code initializes the Logto client, generates the sign-in URI, and redirects the user to the Logto sign-in page. Ensure the redirect URI is correctly configured in Logto. ```go func main() { // ... // Add a link to perform a sign-in request on the home page router.GET("/", func(ctx *gin.Context) { // ... homePage := "

Hello Logto

" + "
" + authState + "
" + // Add link "
Sign In
" ctx.Data(http.StatusOK, "text/html; charset=utf-8", []byte(homePage)) }) // Add a route for handling sign-in requests router.GET("/sign-in", func(ctx *gin.Context) { session := sessions.Default(ctx) logtoClient := client.NewLogtoClient( logtoConfig, &SessionStorage{session: session}, ) // The sign-in request is handled by Logto. // The user will be redirected to the Redirect URI on signed in. signInUri, err := logtoClient.SignIn("http://localhost:3000/callback") if err != nil { ctx.String(http.StatusInternalServerError, err.Error()) return } // Redirect the user to the Logto sign-in page. ctx.Redirect(http.StatusTemporaryRedirect, signInUri) }) // ... } ``` -------------------------------- ### Install Logto SDK with pnpm Source: https://docs.logto.io/quick-starts/expo Install the Logto SDK and its peer dependencies using pnpm. Ensure all peer dependencies are installed directly in your project's package.json. ```bash pnpm add @logto/rn ``` ```bash pnpm add expo-crypto expo-secure-store expo-web-browser @react-native-async-storage/async-storage ``` -------------------------------- ### Install Logto SDK with Yarn Source: https://docs.logto.io/quick-starts/expo Install the Logto SDK and its peer dependencies using Yarn. Ensure all peer dependencies are installed directly in your project's package.json. ```bash yarn add @logto/rn ``` ```bash yarn add expo-crypto expo-secure-store expo-web-browser @react-native-async-storage/async-storage ``` -------------------------------- ### Install Logto SDK with npm Source: https://docs.logto.io/quick-starts/expo Install the Logto SDK and its peer dependencies using npm. Ensure all peer dependencies are installed directly in your project's package.json. ```bash npm i @logto/rn ``` ```bash npm i expo-crypto expo-secure-store expo-web-browser @react-native-async-storage/async-storage ``` -------------------------------- ### Initialize Permit.io Client and Sync User Source: https://docs.logto.io/integrations/permit.io Set up the Permit.io client and functions to sync user data and assign roles. Ensure the API token and PDP endpoint are correctly configured. ```javascript // libraries/permit.js const { Permit } = require('permitio'); // Initialize the Permit.io client const permit = new Permit({ pdp: 'https://cloudpdp.api.permit.io', token: 'your-permitio-api-key', }); // Sync a user with Permit.io export const syncUserToPermit = async (userId, email, firstName, lastName, role = 'viewer') => { // First, sync the user await permit.api.syncUser({ key: userId, email: email || undefined, first_name: firstName || undefined, last_name: lastName || undefined, }); // Then assign a role to the user await permit.api.assignRole({ user: userId, role: role, tenant: 'default', }); return true; }; ``` -------------------------------- ### Initialize Node.js Project with Express Source: https://docs.logto.io/api-protection/nodejs/express Use npm to initialize a new Node.js project and install the Express framework. This is the first step for creating an API server. ```bash npm init -y npm install express ``` -------------------------------- ### Start Rails Development Server Source: https://docs.logto.io/api-protection/ruby/rails Command to start the Rails development server. ```bash rails server ``` -------------------------------- ### Initialize Node.js Project with Fastify Source: https://docs.logto.io/api-protection/nodejs/fastify Use npm to initialize a new Node.js project and install the Fastify framework. This is the first step for building your API. ```bash npm init -y npm install fastify ``` -------------------------------- ### Install dependencies with pnpm Source: https://docs.logto.io/quick-starts/traditional-web Install the necessary dependencies for the Logto integration using pnpm. ```bash pnpm add @logto/js node-fetch@v2 express-session js-base64 ``` -------------------------------- ### Basic Chi Server Setup Source: https://docs.logto.io/api-protection/go/chi Create a basic HTTP server using the Chi router. This sets up the entry point for your API and listens on port 3000. ```go package main import ( "net/http" "github.com/go-chi/chi/v5" ) func main() { r := chi.NewRouter() http.ListenAndServe(":3000", r) } ``` -------------------------------- ### Install dependencies with Yarn Source: https://docs.logto.io/quick-starts/traditional-web Install the necessary dependencies for the Logto integration using Yarn. ```bash yarn add @logto/js node-fetch@v2 express-session js-base64 ```