### UIKit Button Setup for Kinde Login and Registration Source: https://docs.kinde.com/developer-tools/sdks/native/ios-sdk This example demonstrates how to set up UIKit buttons for initiating Kinde's login and registration flows. It includes target-action setup and basic error handling for the authentication results. ```swift import KindeSDK // ... in your ViewController override func viewDidLoad() { super.viewDidLoad() // ... view.addSubview(signInButton) view.addSubview(signUpButton) signInButton.addTarget(self, action: #selector(signIn), for: .primaryActionTriggered) signUpButton.addTarget(self, action: #selector(register), for: .primaryActionTriggered) // ... } @objc private func signIn(_ target: UIButton) { KindeSDKAPI.auth.login { result in switch result { case let .failure(error): if !KindeSDKAPI.auth.isUserCancellationErrorCode(error) { self.alert("Login failed: \(error.localizedDescription)") } case .success: // Do something here break } } } @objc private func register(_ target: UIButton) { KindeSDKAPI.auth.register { result in switch result { case let .failure(error): if !KindeSDKAPI.auth.isUserCancellationErrorCode(error) { self.alert("Registration failed: \(error.localizedDescription)") } case .success: // Do something here break } } } ``` -------------------------------- ### Install Dependencies Source: https://docs.kinde.com/developer-tools/sdks/backend/nextjs-sdk Navigate to your project directory and install necessary dependencies using npm. ```bash cd kinde-nextjs-app-router-starter-kit npm install ``` -------------------------------- ### Install Kinde SDK with bun Source: https://docs.kinde.com/developer-tools/sdks/backend/nextjs-sdk Install the Kinde SDK for Next.js using bun. ```bash bun add @kinde-oss/kinde-auth-nextjs ``` -------------------------------- ### Example Kinde Environment Variables Source: https://docs.kinde.com/developer-tools/sdks/native/react-native-sdk An example configuration of Kinde environment variables for a development setup. ```dotenv KINDE_ISSUER_URL=https://myhost.kinde.com KINDE_POST_CALLBACK_URL=myapp://myhost.kinde.com/kinde_callback KINDE_POST_LOGOUT_REDIRECT_URL=myapp://myhost.kinde.com/kinde_callback KINDE_CLIENT_ID=myclient@live ``` -------------------------------- ### Complete Error Handling Setup with FastAPI Source: https://docs.kinde.com/developer-tools/sdks/backend/python-sdk This example demonstrates how to set up global exception handlers for Kinde SDK exceptions within a FastAPI application. It covers authentication, authorization, and general API errors, ensuring consistent error responses. ```python from fastapi import FastAPI, Request, HTTPException from fastapi.responses import JSONResponse from kinde_sdk.auth.oauth import OAuth from kinde_sdk.exceptions import ( KindeAPIException, KindeAuthenticationException, KindeAuthorizationException, KindeValidationException ) import logging app = FastAPI() oauth = OAuth(framework="fastapi", app=app) logger = logging.getLogger(__name__) # Global exception handler @app.exception_handler(KindeAuthenticationException) async def auth_exception_handler(request: Request, exc: KindeAuthenticationException): logger.warning(f"Authentication failed: {str(exc)}") return JSONResponse( status_code=401, content={"error": "Authentication required", "detail": "Please log in"} ) @app.exception_handler(KindeAuthorizationException) async def authz_exception_handler(request: Request, exc: KindeAuthorizationException): logger.warning(f"Authorization failed: {str(exc)}") return JSONResponse( status_code=403, content={"error": "Access denied", "detail": "Insufficient permissions"} ) @app.exception_handler(KindeAPIException) async def api_exception_handler(request: Request, exc: KindeAPIException): logger.error(f"Kinde API error {exc.status_code}: {str(exc)}") return JSONResponse( status_code=exc.status_code, content={"error": "API error", "detail": "An error occurred with the authentication service"} ) @app.exception_handler(KindeValidationException) async def validation_exception_handler(request: Request, exc: KindeValidationException): logger.warning(f"Validation failed: {str(exc)}") return JSONResponse( status_code=422, content={"error": "Validation error", "detail": str(exc)} ) @app.get("/api/protected") async def protected_endpoint(request: Request): # This will automatically handle exceptions via the handlers above if not await oauth.is_authenticated(request): raise KindeAuthenticationException("Not authenticated") permission = await oauth.get_permission("read:data", request) if not permission.get("isGranted"): raise KindeAuthorizationException("Permission denied") return {"message": "Access granted"} ``` -------------------------------- ### Install Kinde SDK with bun Source: https://docs.kinde.com/developer-tools/sdks/frontend/javascript-sdk Install the Kinde authentication package using bun. This is a prerequisite for initializing the client. ```bash bun add @kinde-oss/kinde-auth-pkce-js ``` -------------------------------- ### Install Kinde SDK with npm Source: https://docs.kinde.com/developer-tools/sdks/frontend/javascript-sdk Install the Kinde authentication package using npm. This is a prerequisite for initializing the client. ```bash npm i @kinde-oss/kinde-auth-pkce-js ``` -------------------------------- ### Install TypeScript SDK with bun Source: https://docs.kinde.com/developer-tools/sdks/backend/typescript-sdk Install the Kinde TypeScript SDK using bun. ```bash bun add @kinde-oss/kinde-typescript-sdk ``` -------------------------------- ### Example Kinde Configuration Source: https://docs.kinde.com/developer-tools/sdks/native/ios-sdk An example of a fully configured Kinde authentication service, demonstrating how to replace placeholder values with actual application details. ```json { "issuer": "https://app.kinde.com", "clientId": "abc@live", "redirectUri": "com.example.App://kinde_callback", "postLogoutRedirectUri": "com.example.App://kinde_logoutcallback", "scope": "offline openid email profile"} ``` -------------------------------- ### Install Kinde Auth SvelteKit SDK with bun Source: https://docs.kinde.com/developer-tools/sdks/backend/sveltekit-sdk Use this command to install the Kinde Auth SvelteKit SDK using bun. ```bash bun add @kinde-oss/kinde-auth-sveltekit ``` -------------------------------- ### Install Kinde SDK with pnpm Source: https://docs.kinde.com/developer-tools/sdks/frontend/javascript-sdk Install the Kinde authentication package using pnpm. This is a prerequisite for initializing the client. ```bash pnpm add @kinde-oss/kinde-auth-pkce-js ``` -------------------------------- ### Install Kinde SDK with yarn Source: https://docs.kinde.com/developer-tools/sdks/frontend/javascript-sdk Install the Kinde authentication package using yarn. This is a prerequisite for initializing the client. ```bash yarn add @kinde-oss/kinde-auth-pkce-js ``` -------------------------------- ### Install Kinde SDK with yarn Source: https://docs.kinde.com/developer-tools/sdks/backend/nextjs-sdk Install the Kinde SDK for Next.js using yarn. ```bash yarn add @kinde-oss/kinde-auth-nextjs ``` -------------------------------- ### Install Kinde SDK with npm Source: https://docs.kinde.com/developer-tools/sdks/backend/nextjs-sdk Install the Kinde SDK for Next.js using npm. ```bash npm i @kinde-oss/kinde-auth-nextjs ``` -------------------------------- ### Install Kinde Auth SvelteKit SDK with npm Source: https://docs.kinde.com/developer-tools/sdks/backend/sveltekit-sdk Use this command to install the Kinde Auth SvelteKit SDK using npm. ```bash npm i @kinde-oss/kinde-auth-sveltekit ``` -------------------------------- ### Install Kinde Auth SvelteKit SDK with pnpm Source: https://docs.kinde.com/developer-tools/sdks/backend/sveltekit-sdk Use this command to install the Kinde Auth SvelteKit SDK using pnpm. ```bash pnpm add @kinde-oss/kinde-auth-sveltekit ``` -------------------------------- ### Install Kinde Auth SvelteKit SDK with yarn Source: https://docs.kinde.com/developer-tools/sdks/backend/sveltekit-sdk Use this command to install the Kinde Auth SvelteKit SDK using yarn. ```bash yarn add @kinde-oss/kinde-auth-sveltekit ``` -------------------------------- ### Install Kinde Python SDK Source: https://docs.kinde.com/developer-tools/sdks/backend/python-sdk Install the Kinde Python SDK using pip. This command should be run in your terminal. ```bash pip install kinde-python-sdk ``` -------------------------------- ### Install TypeScript SDK with npm Source: https://docs.kinde.com/developer-tools/sdks/backend/typescript-sdk Install the Kinde TypeScript SDK using npm. ```bash npm i @kinde-oss/kinde-typescript-sdk ``` -------------------------------- ### Install Required Dependencies with pnpm Source: https://docs.kinde.com/developer-tools/sdks/native/react-native-sdk Install the necessary dependencies for the Kinde SDK using pnpm. ```bash pnpm add react-native-app-auth react-native-keychain react-native-get-random-values ``` -------------------------------- ### Install Kinde React SDK with bun Source: https://docs.kinde.com/developer-tools/sdks/frontend/react-sdk Install the Kinde React SDK using bun. This command adds the Kinde authentication package to your project. ```bash bun add @kinde-oss/kinde-auth-react ``` -------------------------------- ### Install the Kinde Ruby SDK Source: https://docs.kinde.com/developer-tools/sdks/backend/ruby-sdk Install the Kinde Ruby SDK using Bundler. Ensure you have a Gemfile in your project root. ```ruby bundle add kinde_sdk ``` -------------------------------- ### Install Kinde Ruby SDK Source: https://docs.kinde.com/developer-tools/sdks/backend/ruby-sdk Install the Kinde Ruby SDK using Bundler. Ensure you have a Gemfile in your project. ```ruby gem 'kinde-sdk-ruby' ``` -------------------------------- ### Start Development Server Source: https://docs.kinde.com/developer-tools/sdks/frontend/javascript-sdk Run the development server using npm to launch your application locally. ```bash npm run dev ``` -------------------------------- ### Start Development Server with bun Source: https://docs.kinde.com/developer-tools/sdks/frontend/javascript-sdk Run the development server using bun to launch your application locally. ```bash bun run dev ``` -------------------------------- ### Get Access Token Source: https://docs.kinde.com/developer-tools/sdks/native/android-sdk This example shows how to retrieve the current access token after a user has logged in. The access token is used to authenticate API requests. ```kotlin lifecycleScope.launch { val token = kindeClient.getAccessToken() if (token != null) { // Use the access token for API calls Log.d("Kinde", "Access Token: $token") } else { Log.w("Kinde", "No access token available") } } ``` -------------------------------- ### FastAPI Permission Check for Listing Todos Source: https://docs.kinde.com/developer-tools/sdks/backend/python-sdk Example of checking 'read:todos' permission in a FastAPI GET endpoint. Raises an HTTPException if permission is denied. ```python @app.get("/todos") async def list_todos(request: Request): permission = await oauth.get_permission("read:todos", request) if not permission["isGranted"]: raise HTTPException(status_code=403, detail="Permission denied") # List todos logic... return {"todos": []} ``` -------------------------------- ### Get User Profile Source: https://docs.kinde.com/developer-tools/sdks/backend/sveltekit-sdk This example demonstrates how to retrieve the authenticated user's profile information. It assumes the user's session is already established. ```javascript import type { PageServerLoad } from './$types'; export const load: PageServerLoad = async ({ locals }) => { // 'locals.user' is set in the handle hook if authentication is successful if (locals.user) { return { user: locals.user }; } // Handle cases where user might not be available (e.g., if route protection fails) return { user: null }; }; ``` -------------------------------- ### Create Environment File Source: https://docs.kinde.com/developer-tools/sdks/backend/nextjs-sdk Copy the sample environment file to create your local environment configuration. ```bash cp .env.local.sample .env.local ``` -------------------------------- ### Get User Details in Swift Source: https://docs.kinde.com/developer-tools/sdks/native/ios-sdk This function retrieves the current user's details using the Kinde SDK. The example shows the expected structure of the returned User object. ```swift KindeSDKAPI.auth.getUserDetails()// User(id: 1233, email: "dave@smith.com", given_name: "Dave", family_name: "Smith") ``` -------------------------------- ### Get Organization Context in FastAPI Source: https://docs.kinde.com/developer-tools/sdks/backend/python-sdk This example shows how to retrieve organization-specific claims like 'org_code' and 'org_name' within a FastAPI application. It requires the OAuth client to be initialized with the FastAPI framework. ```python from fastapi import FastAPI, Request from kinde_sdk.auth.oauth import OAuth app = FastAPI() oauth = OAuth(framework="fastapi", app=app) @app.get("/organization-info") async def get_org_info(request: Request): org_code = await oauth.get_claim("org_code", request) org_name = await oauth.get_claim("org_name", request) return { "org_code": org_code["value"], "org_name": org_name["value"] if org_name else None } ``` -------------------------------- ### Get User Profile Source: https://docs.kinde.com/developer-tools/sdks/frontend/react-sdk This example demonstrates how to retrieve the authenticated user's profile information using the `useKindeAuth` hook. The profile object contains details like name, email, and picture. ```javascript import React from 'react'; import { useKindeAuth } from '@kinde-oss/kinde-auth-nextjs'; function UserProfile() { const { user } = useKindeAuth(); if (!user) { return
Email: {user.email}