NORY-14: instantiate all Kratos and Hydra APIs (dashboard)

This commit is contained in:
Markus Thielker 2024-12-01 15:34:32 +01:00
parent 8c74eddf50
commit 215d47e888
No known key found for this signature in database
6 changed files with 97 additions and 18 deletions

View file

@ -1,6 +1,6 @@
import { NextResponse } from 'next/server';
import { getFrontendApi } from '@/ory/sdk/hydra';
import { cookies } from 'next/headers';
import { getFrontendApi } from '@/ory/sdk/server';
export async function middleware() {

View file

@ -3,7 +3,7 @@
import { AxiosError } from 'axios';
import { DependencyList, useEffect, useState } from 'react';
import { kratos } from './sdk/kratos';
import { kratos } from './sdk/client';
// Returns a function which will log the user out
export function LogoutLink(deps?: DependencyList) {

View file

@ -1,2 +1,2 @@
export * from './hooks';
export * from './sdk/kratos';
export * from './sdk/client';

View file

@ -1,15 +0,0 @@
'use server';
import { Configuration, OAuth2Api } from '@ory/client';
// implemented as a function because of 'use server'
export default async function getHydra() {
return new OAuth2Api(new Configuration(
new Configuration({
basePath: process.env.ORY_HYDRA_ADMIN_URL,
baseOptions: {
withCredentials: true,
},
}),
));
}

View file

@ -0,0 +1,94 @@
'use server';
import { Configuration, FrontendApi, IdentityApi, MetadataApi, OAuth2Api } from '@ory/client';
// ####################################################################################
// OAuth2 API
// ####################################################################################
const oAuth2Api = new OAuth2Api(new Configuration(
{
basePath: process.env.ORY_HYDRA_ADMIN_URL,
baseOptions: {
withCredentials: true,
},
},
));
export async function getOAuth2Api() {
return oAuth2Api;
}
// ####################################################################################
// Hydra Metadata API
// ####################################################################################
const hydraMetadataApi = new MetadataApi(new Configuration(
{
basePath: process.env.ORY_HYDRA_ADMIN_URL,
baseOptions: {
withCredentials: true,
},
},
));
export async function getHydraMetadataApi() {
return hydraMetadataApi;
}
// ####################################################################################
// Frontend API
// ####################################################################################
const frontendApi = new FrontendApi(
new Configuration({
basePath: process.env.NEXT_PUBLIC_ORY_KRATOS_URL,
baseOptions: {
withCredentials: true,
},
}),
);
export async function getFrontendApi() {
return frontendApi;
}
// ####################################################################################
// Identity API
// ####################################################################################
const identityApi = new IdentityApi(new Configuration(
{
basePath: process.env.ORY_KRATOS_ADMIN_URL,
baseOptions: {
withCredentials: true,
},
},
));
export async function getIdentityApi() {
return identityApi;
}
// ####################################################################################
// Kratos Metadata API
// ####################################################################################
const kratosMetadataApi = new MetadataApi(
new Configuration(
{
basePath: process.env.ORY_KRATOS_ADMIN_URL,
baseOptions: {
withCredentials: true,
},
},
));
export async function getKratosMetadataApi() {
return kratosMetadataApi;
}