Highly ambitious ATProtocol AppView service and sdks
at main 2.8 kB view raw
1#!/bin/bash 2# Register OAuth client for @slices/cli 3 4set -e 5 6# Configuration 7AIP_BASE_URL="${AIP_BASE_URL:-http://localhost:8081}" 8CLIENT_NAME="Slices CLI" 9 10echo "🚀 Registering OAuth client for @slices/cli" 11echo "📡 AIP Server: $AIP_BASE_URL" 12echo 13 14# Check if AIP is running 15echo "🔍 Checking if AIP server is running..." 16if ! curl -s "$AIP_BASE_URL/.well-known/oauth-authorization-server" > /dev/null; then 17 echo "❌ Error: AIP server is not running at $AIP_BASE_URL" 18 echo " Please start AIP first:" 19 echo " docker-compose up -d aip" 20 exit 1 21fi 22echo "✅ AIP server is running" 23echo 24 25# Register the client 26echo "📝 Registering OAuth client..." 27RESPONSE=$(curl -s -X POST "$AIP_BASE_URL/oauth/clients/register" \ 28 -H "Content-Type: application/json" \ 29 -d '{ 30 "client_name": "'"$CLIENT_NAME"'", 31 "grant_types": ["urn:ietf:params:oauth:grant-type:device_code", "refresh_token"], 32 "response_types": ["device_code"], 33 "token_endpoint_auth_method": "none", 34 "application_type": "native", 35 "software_id": "slices-cli", 36 "software_version": "0.1.0", 37 "scope": "atproto transition:generic repo:network.slices.slice repo:network.slices.lexicon repo:network.slices.actor.profile repo:network.slices.waitlist.request" 38 }' \ 39 -w "\nHTTP_STATUS:%{http_code}") 40 41# Extract HTTP status 42HTTP_STATUS=$(echo "$RESPONSE" | tail -n1 | cut -d: -f2) 43BODY=$(echo "$RESPONSE" | sed '$ d') 44 45if [ "$HTTP_STATUS" -eq 201 ] || [ "$HTTP_STATUS" -eq 200 ]; then 46 echo "✅ Client registered successfully!" 47 echo 48 echo "📋 Client Details:" 49 echo "$BODY" | jq '.' 50 echo 51 # Extract the generated client_id 52 GENERATED_CLIENT_ID=$(echo "$BODY" | jq -r '.client_id') 53 echo 54 echo "🎯 You can now use the Slices CLI:" 55 echo " deno run --allow-all src/mod.ts login --client-id $GENERATED_CLIENT_ID" 56 echo 57 echo "💡 Or set the client ID as default by updating the CLI code to use:" 58 echo " DEFAULT_CLIENT_ID = \"$GENERATED_CLIENT_ID\"" 59elif [ "$HTTP_STATUS" -eq 409 ]; then 60 echo "ℹ️ Client already exists (HTTP 409)" 61 echo 62 echo "🎯 You can use the Slices CLI with the existing client:" 63 echo " deno run --allow-all src/mod.ts login" 64 echo " # Note: Using default client ID 'slices-cli'" 65elif [ "$HTTP_STATUS" -eq 404 ]; then 66 echo "❌ Client registration endpoint not found (HTTP 404)" 67 echo " This likely means client management API is disabled." 68 echo " Enable it by setting: ENABLE_CLIENT_API=true" 69 echo " Or manually register the client through AIP admin interface." 70 exit 1 71else 72 echo "❌ Client registration failed (HTTP $HTTP_STATUS)" 73 echo "Response:" 74 echo "$BODY" | jq '.' 2>/dev/null || echo "$BODY" 75 exit 1 76fi