mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-07-19 03:10:03 +00:00
feat(auth,ui): support github sign-in in the UI (#2545)
# What does this PR do? Uses NextAuth to add github sign in support. ## Test Plan Start server with auth configured as in https://github.com/meta-llama/llama-stack/pull/2509 https://github.com/user-attachments/assets/61ff7442-f601-4b39-8686-5d0afb3b45ac
This commit is contained in:
parent
c8bac888af
commit
daf660c4ea
23 changed files with 577 additions and 81 deletions
38
llama_stack/ui/lib/auth.ts
Normal file
38
llama_stack/ui/lib/auth.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
import { NextAuthOptions } from "next-auth";
|
||||
import GithubProvider from "next-auth/providers/github";
|
||||
|
||||
export const authOptions: NextAuthOptions = {
|
||||
providers: [
|
||||
GithubProvider({
|
||||
clientId: process.env.GITHUB_CLIENT_ID!,
|
||||
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
|
||||
authorization: {
|
||||
params: {
|
||||
scope: "read:user user:email",
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
debug: process.env.NODE_ENV === "development",
|
||||
callbacks: {
|
||||
async jwt({ token, account }) {
|
||||
// Persist the OAuth access_token to the token right after signin
|
||||
if (account) {
|
||||
token.accessToken = account.access_token;
|
||||
}
|
||||
return token;
|
||||
},
|
||||
async session({ session, token }) {
|
||||
// Send properties to the client, like an access_token from a provider.
|
||||
session.accessToken = token.accessToken as string;
|
||||
return session;
|
||||
},
|
||||
},
|
||||
pages: {
|
||||
signIn: "/auth/signin",
|
||||
error: "/auth/signin", // Redirect errors to our custom page
|
||||
},
|
||||
session: {
|
||||
strategy: "jwt",
|
||||
},
|
||||
};
|
|
@ -1,6 +0,0 @@
|
|||
import LlamaStackClient from "llama-stack-client";
|
||||
|
||||
export const client = new LlamaStackClient({
|
||||
baseURL:
|
||||
typeof window !== "undefined" ? `${window.location.origin}/api` : "/api",
|
||||
});
|
56
llama_stack/ui/lib/config-validator.ts
Normal file
56
llama_stack/ui/lib/config-validator.ts
Normal file
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* Validates environment configuration for the application
|
||||
* This is called during server initialization
|
||||
*/
|
||||
export function validateServerConfig() {
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
console.log("🚀 Starting Llama Stack UI Server...");
|
||||
|
||||
// Check optional configurations
|
||||
const optionalConfigs = {
|
||||
NEXTAUTH_URL: process.env.NEXTAUTH_URL || "http://localhost:8322",
|
||||
LLAMA_STACK_BACKEND_URL:
|
||||
process.env.LLAMA_STACK_BACKEND_URL || "http://localhost:8321",
|
||||
LLAMA_STACK_UI_PORT: process.env.LLAMA_STACK_UI_PORT || "8322",
|
||||
GITHUB_CLIENT_ID: process.env.GITHUB_CLIENT_ID,
|
||||
GITHUB_CLIENT_SECRET: process.env.GITHUB_CLIENT_SECRET,
|
||||
};
|
||||
|
||||
console.log("\n📋 Configuration:");
|
||||
console.log(` - NextAuth URL: ${optionalConfigs.NEXTAUTH_URL}`);
|
||||
console.log(` - Backend URL: ${optionalConfigs.LLAMA_STACK_BACKEND_URL}`);
|
||||
console.log(` - UI Port: ${optionalConfigs.LLAMA_STACK_UI_PORT}`);
|
||||
|
||||
// Check GitHub OAuth configuration
|
||||
if (
|
||||
!optionalConfigs.GITHUB_CLIENT_ID ||
|
||||
!optionalConfigs.GITHUB_CLIENT_SECRET
|
||||
) {
|
||||
console.log(
|
||||
"\n📝 GitHub OAuth not configured (authentication features disabled)",
|
||||
);
|
||||
console.log(" To enable GitHub OAuth:");
|
||||
console.log(" 1. Go to https://github.com/settings/applications/new");
|
||||
console.log(
|
||||
" 2. Set Application name: Llama Stack UI (or your preferred name)",
|
||||
);
|
||||
console.log(" 3. Set Homepage URL: http://localhost:8322");
|
||||
console.log(
|
||||
" 4. Set Authorization callback URL: http://localhost:8322/api/auth/callback/github",
|
||||
);
|
||||
console.log(
|
||||
" 5. Create the app and copy the Client ID and Client Secret",
|
||||
);
|
||||
console.log(" 6. Add them to your .env.local file:");
|
||||
console.log(" GITHUB_CLIENT_ID=your_client_id");
|
||||
console.log(" GITHUB_CLIENT_SECRET=your_client_secret");
|
||||
} else {
|
||||
console.log(" - GitHub OAuth: ✅ Configured");
|
||||
}
|
||||
|
||||
console.log("");
|
||||
}
|
||||
}
|
||||
|
||||
// Call this function when the module is imported
|
||||
validateServerConfig();
|
Loading…
Add table
Add a link
Reference in a new issue