Skip to content

Commit

Permalink
Extended auth provider param options;
Browse files Browse the repository at this point in the history
  • Loading branch information
stef-coenen committed Sep 15, 2023
1 parent 9771adf commit bac1714
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/feed-app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<!-- <base href="/feed/" /> -->
<meta name="viewport" content="width=device-width, initial-scale=1" />

<link rel="apple-touch-icon" sizes="180x180" href="/icons/apple-touch-icon.png" />
Expand Down
7 changes: 4 additions & 3 deletions packages/feed-app/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import '@youfoundation/ui-lib/dist/style.css';
import './App.css';
import useAuth from '../hooks/auth/useAuth';

const AUTH_PATH = '/auth';
export const ROOT_PATH = '/';
const AUTH_PATH = ROOT_PATH + '/auth';

import { ErrorBoundary } from '@youfoundation/common-app';

Expand All @@ -38,7 +39,7 @@ function App() {
createRoutesFromElements(
<>
<Route
path=""
path={ROOT_PATH}
element={
<ErrorBoundary>
<Suspense fallback={<></>}>
Expand Down Expand Up @@ -116,7 +117,7 @@ const RootRoute = ({ children }: { children: ReactNode }) => {
return <></>;
}

return <Navigate to={`/about`} />;
return <Navigate to={`${ROOT_PATH}/about`} />;
}

return <>{children}</>;
Expand Down
3 changes: 2 additions & 1 deletion packages/feed-app/src/components/Auth/LoginBox/LoginBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { IS_DARK_CLASSNAME, LoadingBlock } from '@youfoundation/common-app';
import { stringifyToQueryParams } from '@youfoundation/js-lib/helpers';
import { Helmet } from 'react-helmet-async';
import { useQuery } from '@tanstack/react-query';
import { ROOT_PATH } from '../../../app/App';

const useParams = (returnUrl: string) => {
const { getAuthorizationParameters } = useYouAuthAuthorization();
Expand All @@ -13,7 +14,7 @@ const useParams = (returnUrl: string) => {
};

export const LoginBox = () => {
const { data: authParams, isLoading } = useParams('/');
const { data: authParams, isLoading } = useParams(ROOT_PATH);

if (isLoading)
return (
Expand Down
6 changes: 5 additions & 1 deletion packages/feed-app/src/hooks/auth/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
retrieveEccKey,
throwAwayTheECCKey,
} from '@youfoundation/js-lib/auth';
import { ROOT_PATH } from '../../app/App';

export const drives = [
{
Expand Down Expand Up @@ -115,12 +116,15 @@ export const useYouAuthAuthorization = () => {
// Persist key for usage on finalize
await saveEccKey(eccKey);

const finalizeUrl = `${window.location.origin}/auth/finalize`;
const finalizeUrl = `${window.location.origin}${ROOT_PATH}/auth/finalize`;
return getRegistrationParams(
finalizeUrl,
appName,
appId,
[10, 30, 50, 80, 130, 210],
undefined,
drives,
undefined,
eccKey.publicKey,
window.location.host,
undefined,
Expand Down
3 changes: 2 additions & 1 deletion packages/feed-app/src/templates/About/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { NoLayout } from '../../components/ui/Layout/Layout';
import LoginNav from '../../components/Auth/LoginNav/LoginNav';

import { ActionLink, Logo, t } from '@youfoundation/common-app';
import { ROOT_PATH } from '../../app/App';

const About = () => {
return (
Expand Down Expand Up @@ -59,7 +60,7 @@ const About = () => {
<div className="relative z-10">
<h2 className="mb-5 text-center text-5xl">{t('Keep your socials yours')}</h2>
<div className="flex justify-center">
<ActionLink href="/auth" className="w-auto">
<ActionLink href={`${ROOT_PATH}/auth`} className="w-auto">
{t('Go to Homebase Feed')}
</ActionLink>
</div>
Expand Down
11 changes: 10 additions & 1 deletion packages/js-lib/src/auth/providers/AuthenticationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export interface AppAuthorizationParams {
n: string;
appId: string;
fn: string;
d: string;
p: string | undefined;
cp: string | undefined;
d: string | undefined;
cd: string | undefined;
return: string;
o?: string;
}
Expand All @@ -42,7 +45,10 @@ export const getRegistrationParams = async (
returnUrl: string,
appName: string,
appId: string,
permissionKeys: number[] | undefined,
circlePermissionKeys: number[] | undefined,
drives: { a: string; t: string; n: string; d: string; p: number }[],
circleDrives: { a: string; t: string; n: string; d: string; p: number }[] | undefined,
eccPublicKey: CryptoKey,
host?: string,
clientFriendlyName?: string,
Expand All @@ -54,7 +60,10 @@ export const getRegistrationParams = async (
n: appName,
appId: appId,
fn: clientFriendly,
p: permissionKeys?.join(','),
cp: circlePermissionKeys?.join(','),
d: JSON.stringify(drives),
cd: circleDrives ? JSON.stringify(circleDrives) : undefined,
return: 'backend-will-decide',
o: undefined,
};
Expand Down

0 comments on commit bac1714

Please sign in to comment.