Spaces:
Runtime error
Runtime error
File size: 1,016 Bytes
31f62e8 7d29959 31f62e8 7d29959 31f62e8 7d29959 31f62e8 7d29959 31f62e8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
export async function POST(req: Request) {
const { code } = await req.json();
const REDIRECT_URI = `https://${process.env.SPACE_HOST}/login/callback`;
const Authorization = `Basic ${Buffer.from(
`${process.env.OAUTH_CLIENT_ID}:${process.env.OAUTH_CLIENT_SECRET}`
).toString("base64")}`;
const request = await fetch("https://huggingface.co./oauth/token", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization,
},
body: new URLSearchParams({
grant_type: "authorization_code",
code,
redirect_uri: REDIRECT_URI,
}),
});
const response = await request
.clone()
.json()
.catch(() => ({}));
if (response.error) return Response.json({ status: 401, ok: false, message: response.error_description });
return Response.json(
{
access_token: response.access_token,
experes_in: response.expires_in,
status: 200,
ok: true
}
)
} |