-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: creating api throught dashboard
- Loading branch information
Nicolas Burtey
committed
Oct 26, 2023
1 parent
5288876
commit 960848b
Showing
24 changed files
with
443 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# REPLACE THIS IT IS FOR TESTING | ||
NEXTAUTH_URL=https://c890-2405-201-301c-5b67-89d6-bd56-6afb-6294.ngrok-free.app | ||
NEXTAUTH_URL=http://localhost:3001 | ||
NEXTAUTH_SECRET="thisismysecret" | ||
# 2db7666c39074da4b399e8b5116ef2c6 | ||
# 2cc1869e52ad47df848a6519b63bb4f4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { getOauth2Client } from "../client" | ||
import { env } from "@/env" | ||
import { CallbackParamsType, TokenSet } from "openid-client" | ||
|
||
export default async function page({ searchParams }: {searchParams: URLSearchParams}) { | ||
const client = await getOauth2Client() | ||
|
||
const params = searchParams as unknown as CallbackParamsType | ||
|
||
let tokenSet: TokenSet | ||
|
||
// should use .oauthCallback if idtoken is not present | ||
try { | ||
tokenSet = await client.callback( | ||
`${env.NEXTAUTH_URL}/keys/create/callback`, | ||
params, | ||
{ state: params.state }, | ||
) | ||
} catch (err) { | ||
console.error(err) | ||
return <div>error: {err.message}</div> | ||
} | ||
|
||
return ( | ||
<> | ||
This is your api key: {tokenSet.access_token} | ||
<br /> | ||
You won't see this key again, so copy it now | ||
<br /> | ||
Meta: {JSON.stringify({...tokenSet})} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { env } from "@/env" | ||
import { Issuer } from "openid-client" | ||
|
||
const clientId = env.CLIENT_ID_APP_API_KEY | ||
const clientSecret = env.CLIENT_SECRET_APP_API_KEY | ||
|
||
export const getOauth2Client = async () => { | ||
const GaloyIssuer = await Issuer.discover(env.HYDRA_PUBLIC) | ||
|
||
return new GaloyIssuer.Client({ | ||
client_id: clientId, | ||
client_secret: clientSecret, | ||
redirect_uris: [`${env.NEXTAUTH_URL}/keys/create/callback`], | ||
response_types: ["code"], | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { redirect } from "next/navigation" | ||
import { getOauth2Client } from "./client" | ||
|
||
import { cookies } from "next/headers" | ||
|
||
const crypto = require("crypto") | ||
|
||
function generateSecureRandomString(length: number) { | ||
return crypto.randomBytes(length).toString("hex").slice(0, length) | ||
} | ||
|
||
export async function GET(request: Request) { | ||
cookies().delete("ory_hydra_session_dev") | ||
|
||
const client = await getOauth2Client() | ||
const randomString = generateSecureRandomString(16) | ||
|
||
const authorizationUri = client.authorizationUrl({ | ||
scope: "transactions:read payments:send openid", | ||
state: randomString, | ||
}) | ||
|
||
redirect(authorizationUri) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"use server"; | ||
|
||
export const deleteKey = async (index: string) => { | ||
console.log(index, "session id") | ||
} |
Oops, something went wrong.