-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
57 additions
and
88 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,11 +1,25 @@ | ||
'use server'; | ||
|
||
import React from 'react'; | ||
|
||
import oidc from '@/config/oidc.mjs'; | ||
import queryString from 'query-string'; | ||
import { redirect } from 'next/navigation'; | ||
// import { getUserData } from '@/app/actions/user'; | ||
|
||
import Auth from './Auth'; | ||
const { client, server } = oidc; | ||
const { url } = server; | ||
const { client_id, redirect_uri, origin } = client; | ||
|
||
export default async function AuthServer() { | ||
return <Auth oidc={oidc} />; | ||
const query = queryString.stringify({ | ||
client_id, | ||
redirect_uri: `${origin}${redirect_uri}`, | ||
response_type: 'code', | ||
scope: 'openid profile email groups offline_access', | ||
}); | ||
// todo validate | ||
// const user = await getUserData(); | ||
// if (!user) { | ||
// redirect(`${url}/oidc/auth?${query}`); | ||
// } | ||
redirect(`${url}/oidc/auth?${query}`); | ||
} |
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,40 +1,29 @@ | ||
'use client'; | ||
|
||
import { useRouter, useSearchParams } from 'next/navigation'; | ||
import { AUTH_DATA } from '@/utils/constants'; | ||
import { useRouter } from 'next/navigation'; | ||
import React from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
|
||
import oidc from '@/config/oidc.mjs'; | ||
|
||
const { AUTH_DATA } = oidc; | ||
|
||
export default function Callback({ redirect_uri }: { redirect_uri: string }) { | ||
const searchParams = useSearchParams(); | ||
export default function Callback({ data: res }: { data: any }) { | ||
const dispatch = useDispatch(); | ||
const router = useRouter(); | ||
const code = searchParams.get('code'); | ||
const fetchAuth = async () => { | ||
fetch(`/oidc/token?code=${code}&redirect_uri=${location.origin}${redirect_uri}`, { | ||
method: 'POST', | ||
}) | ||
.then(res => res.json()) | ||
.then(res => { | ||
if (res.data?.errors) { | ||
console.warn(res.data?.errors); | ||
return; | ||
} | ||
if (res.data) { | ||
localStorage.setItem(AUTH_DATA, JSON.stringify(res.data)); | ||
dispatch({ | ||
type: 'SAVE_AUTH_DATA', | ||
authData: res.data, | ||
}); | ||
router.push('/chat'); | ||
} | ||
const saveAuth = async () => { | ||
if (res?.data?.errors) { | ||
console.warn(res?.data?.errors); | ||
return; | ||
} | ||
if (res?.data) { | ||
localStorage.setItem(AUTH_DATA, JSON.stringify(res.data)); | ||
dispatch({ | ||
type: 'SAVE_AUTH_DATA', | ||
authData: res.data, | ||
}); | ||
router.push('/chat'); | ||
} | ||
}; | ||
React.useEffect(() => { | ||
fetchAuth(); | ||
saveAuth(); | ||
}, []); | ||
return <> </>; | ||
} |
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,11 +1,15 @@ | ||
'use server'; | ||
|
||
import React from 'react'; | ||
|
||
import oidc from '@/config/oidc.mjs'; | ||
|
||
import Callback from './Callback'; | ||
|
||
export default async function CallbackServer() { | ||
return <Callback redirect_uri={oidc.client.redirect_uri} />; | ||
export default async function CallbackServer({ searchParams }: any) { | ||
const { code } = searchParams; | ||
const { origin, redirect_uri } = oidc.client | ||
const res = await fetch(`${origin}/oidc/token?code=${code}&redirect_uri=${origin}${redirect_uri}`, { | ||
method: 'POST', | ||
}); | ||
const data = await res.json(); | ||
return <Callback data={data} />; | ||
} |
This file was deleted.
Oops, something went wrong.
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,11 +1,13 @@ | ||
'use server'; | ||
|
||
import React from 'react'; | ||
|
||
import oidc from '@/config/oidc.mjs'; | ||
|
||
import Logout from './Logout'; | ||
import oidc from '@/config/oidc.mjs' | ||
import { redirect } from 'next/navigation'; | ||
|
||
export default async function LogoutServer() { | ||
return <Logout oidc={oidc} />; | ||
const { client, server } = oidc; | ||
const { redirect_uri, origin } = client; | ||
const { url } = server; | ||
redirect(`${url}/oidc/logout/remove-auth-data?redirect=${encodeURIComponent( | ||
`${url}/oidc/auth?redirect_uri=${origin}${redirect_uri}&response_type=code&scope=openid+profile+email+groups+offline_access` | ||
)}`); | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export const AUTH_DATA = 'authData'; |
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