Skip to content

Commit 0d8fefe

Browse files
Merge branch 'main' into fix/configurable-token-url
2 parents da7a499 + 735f4cb commit 0d8fefe

9 files changed

Lines changed: 27 additions & 5 deletions

File tree

console/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
VITE_POLARIS_API_URL=http://localhost:8181
22
VITE_POLARIS_REALM=POLARIS # optional
3+
VITE_POLARIS_PRINCIPAL_SCOPE=PRINCIPAL_ROLE:ALL # optional
34
VITE_OAUTH_TOKEN_URL=http://localhost:8181/api/catalog/v1/oauth/tokens

console/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ VITE_POLARIS_API_URL=http://polaris-polaris-1:8181
66
# The realm identifier for Polaris
77
VITE_POLARIS_REALM=POLARIS
88

9+
# Polaris Principal Scope
10+
VITE_POLARIS_PRINCIPAL_SCOPE=PRINCIPAL_ROLE:ALL
11+
912
# Docker Configuration
1013
# Port on which the UI will be accessible (default: 3000)
1114
PORT=3000

console/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Create a `.env` file based on `.env.example`:
4646
```env
4747
VITE_POLARIS_API_URL=http://localhost:8181
4848
VITE_POLARIS_REALM=POLARIS
49+
VITE_POLARIS_PRINCIPAL_SCOPE=PRINCIPAL_ROLE:ALL
4950
VITE_POLARIS_REALM_HEADER_NAME=Polaris-Realm # optional, defaults to "Polaris-Realm"
5051
VITE_OAUTH_TOKEN_URL= # optional, defaults to /api/catalog/v1/oauth/tokens
5152
```

console/docker/generate-config.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ cat > /opt/app-root/src/config.js << EOF
2626
window.APP_CONFIG = {
2727
VITE_POLARIS_API_URL: '${VITE_POLARIS_API_URL}',
2828
VITE_POLARIS_REALM: '${VITE_POLARIS_REALM}',
29+
VITE_POLARIS_PRINCIPAL_SCOPE: '${VITE_POLARIS_PRINCIPAL_SCOPE}',
2930
VITE_OAUTH_TOKEN_URL: '${VITE_OAUTH_TOKEN_URL}',
3031
VITE_POLARIS_REALM_HEADER_NAME: '${VITE_POLARIS_REALM_HEADER_NAME}'
3132
};

console/helm/templates/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ spec:
4848
value: {{ .Values.env.polarisApiUrl | quote }}
4949
- name: VITE_POLARIS_REALM
5050
value: {{ .Values.env.polarisRealm | quote }}
51+
- name: VITE_POLARIS_PRINCIPAL_SCOPE
52+
value: { { .Values.env.polarisPrincipalScope | quote } }
5153
- name: VITE_OAUTH_TOKEN_URL
5254
value: {{ .Values.env.oauthTokenUrl | quote }}
5355
readinessProbe:

console/src/api/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const authApi = {
4343
formData.append("grant_type", "client_credentials")
4444
formData.append("client_id", clientId)
4545
formData.append("client_secret", clientSecret)
46-
formData.append("scope", "PRINCIPAL_ROLE:ALL")
46+
formData.append("scope", scope)
4747

4848
const headers: Record<string, string> = {
4949
"Content-Type": "application/x-www-form-urlencoded",

console/src/hooks/useAuth.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { authApi } from "@/api/auth"
2323

2424
interface AuthContextType {
2525
isAuthenticated: boolean
26-
login: (clientId: string, clientSecret: string, realm: string) => Promise<void>
26+
login: (clientId: string, clientSecret: string, scope: string, realm: string) => Promise<void>
2727
logout: () => void
2828
loading: boolean
2929
}
@@ -34,13 +34,13 @@ export function AuthProvider({ children }: { children: ReactNode }) {
3434
const [isAuthenticated, setIsAuthenticated] = useState<boolean>(false)
3535
const [loading] = useState<boolean>(false)
3636

37-
const login = async (clientId: string, clientSecret: string, realm: string) => {
37+
const login = async (clientId: string, clientSecret: string, scope: string, realm: string) => {
3838
try {
3939
// Store realm in localStorage (non-sensitive configuration)
4040
if (realm) {
4141
localStorage.setItem("polaris_realm", realm)
4242
}
43-
await authApi.getToken(clientId, clientSecret, realm)
43+
await authApi.getToken(clientId, clientSecret, scope, realm)
4444
setIsAuthenticated(true)
4545
} catch (error) {
4646
setIsAuthenticated(false)

console/src/lib/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
interface AppConfig {
2121
VITE_POLARIS_API_URL?: string
2222
VITE_POLARIS_REALM?: string
23+
VITE_POLARIS_PRINCIPAL_SCOPE: string
2324
VITE_OAUTH_TOKEN_URL?: string
2425
VITE_POLARIS_REALM_HEADER_NAME?: string
2526
}
@@ -53,6 +54,7 @@ function getConfig<T extends string | undefined>(
5354
export const config = {
5455
POLARIS_API_URL: getConfig('VITE_POLARIS_API_URL', ''),
5556
POLARIS_REALM: getConfig('VITE_POLARIS_REALM', ''),
57+
POLARIS_PRINCIPAL_SCOPE: getConfig('VITE_POLARIS_PRINCIPAL_SCOPE', ''),
5658
OAUTH_TOKEN_URL: getConfig('VITE_OAUTH_TOKEN_URL', ''),
5759
REALM_HEADER_NAME: getConfig('VITE_POLARIS_REALM_HEADER_NAME', 'Polaris-Realm'),
5860
}

console/src/pages/Login.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export function Login() {
3232
const [clientSecret, setClientSecret] = useState("")
3333
// Initialize realm with value from .env file if present
3434
const [realm, setRealm] = useState(import.meta.env.VITE_POLARIS_REALM || "")
35+
const [scope, setScope] = useState(import.meta.env.VITE_POLARIS_PRINCIPAL_SCOPE || "")
3536
const [error, setError] = useState("")
3637
const [loading, setLoading] = useState(false)
3738
const { login } = useAuth()
@@ -43,7 +44,7 @@ export function Login() {
4344
setLoading(true)
4445

4546
try {
46-
await login(clientId, clientSecret, realm)
47+
await login(clientId, clientSecret, scope, realm)
4748
navigate("/")
4849
} catch (err) {
4950
setError(
@@ -100,6 +101,17 @@ export function Login() {
100101
placeholder="Enter your realm"
101102
/>
102103
</div>
104+
<div className="space-y-2">
105+
<Label htmlFor="scope">Scope</Label>
106+
<Input
107+
id="scope"
108+
type="text"
109+
value={scope}
110+
onChange={(e) => setScope(e.target.value)}
111+
required
112+
placeholder="Enter the scope"
113+
/>
114+
</div>
103115
{error && (
104116
<div className="rounded-md bg-destructive/10 p-3 text-sm text-destructive">
105117
{error}

0 commit comments

Comments
 (0)