mirror of
https://codeberg.org/MarkusThielker/next-ory.git
synced 2025-04-19 00:51:18 +00:00
NORY-14: instantiate all Kratos and Hydra APIs (dashboard)
This commit is contained in:
parent
8c74eddf50
commit
215d47e888
6 changed files with 97 additions and 18 deletions
|
@ -1,6 +1,6 @@
|
||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import { getFrontendApi } from '@/ory/sdk/hydra';
|
|
||||||
import { cookies } from 'next/headers';
|
import { cookies } from 'next/headers';
|
||||||
|
import { getFrontendApi } from '@/ory/sdk/server';
|
||||||
|
|
||||||
export async function middleware() {
|
export async function middleware() {
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
import { AxiosError } from 'axios';
|
import { AxiosError } from 'axios';
|
||||||
import { DependencyList, useEffect, useState } from 'react';
|
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
|
// Returns a function which will log the user out
|
||||||
export function LogoutLink(deps?: DependencyList) {
|
export function LogoutLink(deps?: DependencyList) {
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
export * from './hooks';
|
export * from './hooks';
|
||||||
export * from './sdk/kratos';
|
export * from './sdk/client';
|
||||||
|
|
|
@ -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,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
));
|
|
||||||
}
|
|
94
dashboard/src/ory/sdk/server/index.ts
Normal file
94
dashboard/src/ory/sdk/server/index.ts
Normal 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;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue