mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
40 lines
811 B
TypeScript
40 lines
811 B
TypeScript
// Check validity of auth-token
|
|
import { kubeRequest } from "./kube-request";
|
|
|
|
export interface ITokenReview {
|
|
apiVersion: string;
|
|
kind: string;
|
|
status: ITokenReviewStatus;
|
|
}
|
|
|
|
export interface ITokenReviewStatus {
|
|
authenticated: boolean;
|
|
user: {
|
|
username?: string;
|
|
uid?: string;
|
|
groups?: string[];
|
|
};
|
|
error?: string[];
|
|
}
|
|
|
|
export async function reviewToken(authToken: string): Promise<ITokenReviewStatus> {
|
|
try {
|
|
const tokenReview = await kubeRequest<ITokenReview>({
|
|
path: "/apis/authentication.k8s.io/v1/tokenreviews",
|
|
method: "POST",
|
|
data: {
|
|
spec: {
|
|
token: authToken
|
|
}
|
|
}
|
|
});
|
|
return tokenReview.status;
|
|
} catch (err) {
|
|
return {
|
|
authenticated: false,
|
|
user: {},
|
|
error: [err.toString()],
|
|
}
|
|
}
|
|
}
|