uibee 2.8.6 → 2.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/utils/auth/callback.d.ts +1 -1
- package/dist/src/utils/auth/callback.js +5 -3
- package/dist/src/utils/auth/getDomain.d.ts +2 -0
- package/dist/src/utils/auth/getDomain.js +5 -0
- package/dist/src/utils/auth/login.d.ts +1 -1
- package/dist/src/utils/auth/login.js +4 -2
- package/dist/src/utils/auth/logout.d.ts +1 -1
- package/dist/src/utils/auth/logout.js +4 -2
- package/dist/src/utils/auth/token.d.ts +1 -1
- package/dist/src/utils/auth/token.js +5 -3
- package/package.json +1 -1
- package/src/types/utils.d.ts +7 -7
- package/src/utils/auth/callback.ts +6 -4
- package/src/utils/auth/getDomain.ts +7 -0
- package/src/utils/auth/login.ts +4 -2
- package/src/utils/auth/logout.ts +4 -2
- package/src/utils/auth/token.ts +5 -3
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { AuthCallbackProps } from 'uibee/utils';
|
|
2
|
-
export default function authCallback({ req, tokenURL, clientID, clientSecret,
|
|
2
|
+
export default function authCallback({ req, tokenURL, clientID, clientSecret, redirectPath, userInfoURL, tokenRedirectPath }: AuthCallbackProps): Promise<Response>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { NextResponse } from 'next/server';
|
|
2
|
-
|
|
2
|
+
import { getDomain } from './getDomain';
|
|
3
|
+
export default async function authCallback({ req, tokenURL, clientID, clientSecret, redirectPath, userInfoURL, tokenRedirectPath }) {
|
|
4
|
+
const domain = getDomain(req);
|
|
3
5
|
const searchParams = new URL(req.url).searchParams;
|
|
4
6
|
if (!searchParams) {
|
|
5
7
|
return NextResponse.json({ error: 'No search parameters found.' }, { status: 400 });
|
|
@@ -17,7 +19,7 @@ export default async function authCallback({ req, tokenURL, clientID, clientSecr
|
|
|
17
19
|
client_id: clientID,
|
|
18
20
|
client_secret: clientSecret,
|
|
19
21
|
code: code,
|
|
20
|
-
redirect_uri:
|
|
22
|
+
redirect_uri: `${domain}${redirectPath}`,
|
|
21
23
|
grant_type: 'authorization_code',
|
|
22
24
|
}).toString()
|
|
23
25
|
});
|
|
@@ -41,7 +43,7 @@ export default async function authCallback({ req, tokenURL, clientID, clientSecr
|
|
|
41
43
|
});
|
|
42
44
|
}
|
|
43
45
|
const userInfo = await userInfoResponse.json();
|
|
44
|
-
const redirectUrl = new URL(
|
|
46
|
+
const redirectUrl = new URL(`${domain}${tokenRedirectPath}`);
|
|
45
47
|
const params = new URLSearchParams({
|
|
46
48
|
id: userInfo.sub,
|
|
47
49
|
name: userInfo.name,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { NextResponse } from 'next/server';
|
|
2
2
|
import type { AuthLoginProps } from 'uibee/utils';
|
|
3
|
-
export default function AuthLogin({ clientID,
|
|
3
|
+
export default function AuthLogin({ req, clientID, redirectPath, authURL }: AuthLoginProps): Promise<NextResponse<unknown>>;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { NextResponse } from 'next/server';
|
|
2
|
-
|
|
2
|
+
import { getDomain } from './getDomain';
|
|
3
|
+
export default async function AuthLogin({ req, clientID, redirectPath, authURL }) {
|
|
4
|
+
const domain = getDomain(req);
|
|
3
5
|
const state = Math.random().toString(36).substring(5);
|
|
4
6
|
const authQueryParams = new URLSearchParams({
|
|
5
7
|
client_id: clientID,
|
|
6
|
-
redirect_uri:
|
|
8
|
+
redirect_uri: `${domain}${redirectPath}`,
|
|
7
9
|
response_type: 'code',
|
|
8
10
|
scope: 'openid profile email',
|
|
9
11
|
state: state,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { NextResponse } from 'next/server';
|
|
2
2
|
import type { AuthLogoutProps } from 'uibee/utils';
|
|
3
|
-
export default function AuthLogout({
|
|
3
|
+
export default function AuthLogout({ req, path }: AuthLogoutProps): Promise<NextResponse<unknown>>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { NextResponse } from 'next/server';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { getDomain } from './getDomain';
|
|
3
|
+
export default async function AuthLogout({ req, path }) {
|
|
4
|
+
const domain = getDomain(req);
|
|
5
|
+
const response = NextResponse.redirect(new URL(path || '/', domain));
|
|
4
6
|
const cookiesToRemove = [
|
|
5
7
|
'access_token',
|
|
6
8
|
'user_id',
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { NextResponse } from 'next/server';
|
|
2
2
|
import type { AuthTokenProps } from 'uibee/utils';
|
|
3
|
-
export default function AuthToken({ req,
|
|
3
|
+
export default function AuthToken({ req, redirectPath }: AuthTokenProps): Promise<NextResponse<unknown>>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { NextResponse } from 'next/server';
|
|
2
|
-
|
|
2
|
+
import { getDomain } from './getDomain';
|
|
3
|
+
export default async function AuthToken({ req, redirectPath }) {
|
|
4
|
+
const domain = getDomain(req);
|
|
3
5
|
const url = new URL(req.url);
|
|
4
6
|
const token = url.searchParams.get('access_token');
|
|
5
7
|
const btg = url.searchParams.get('btg');
|
|
@@ -9,7 +11,7 @@ export default async function AuthToken({ req, frontendURL, redirectPath }) {
|
|
|
9
11
|
return NextResponse.json({ error: 'No access token provided' }, { status: 400 });
|
|
10
12
|
}
|
|
11
13
|
if (btg) {
|
|
12
|
-
return NextResponse.redirect(new URL(redirect,
|
|
14
|
+
return NextResponse.redirect(new URL(redirect, domain));
|
|
13
15
|
}
|
|
14
16
|
const accessToken = url.searchParams.get('access_token');
|
|
15
17
|
const userID = url.searchParams.get('id');
|
|
@@ -17,7 +19,7 @@ export default async function AuthToken({ req, frontendURL, redirectPath }) {
|
|
|
17
19
|
const userNickname = url.searchParams.get('username');
|
|
18
20
|
const userEmail = url.searchParams.get('email');
|
|
19
21
|
const userGroups = url.searchParams.get('groups');
|
|
20
|
-
const response = NextResponse.redirect(new URL(redirect,
|
|
22
|
+
const response = NextResponse.redirect(new URL(redirect, domain));
|
|
21
23
|
response.cookies.set('access_token', accessToken);
|
|
22
24
|
response.cookies.set('user_id', userID);
|
|
23
25
|
response.cookies.set('user_name', username);
|
package/package.json
CHANGED
package/src/types/utils.d.ts
CHANGED
|
@@ -2,30 +2,30 @@
|
|
|
2
2
|
import { NextRequest } from 'next/server'
|
|
3
3
|
declare module 'uibee/utils' {
|
|
4
4
|
export interface AuthLoginProps {
|
|
5
|
+
req: NextRequest
|
|
5
6
|
clientID: string
|
|
6
|
-
|
|
7
|
+
redirectPath: string
|
|
7
8
|
authURL: string
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export interface AuthCallbackProps {
|
|
11
|
-
req:
|
|
12
|
+
req: NextRequest
|
|
12
13
|
tokenURL: string
|
|
13
14
|
clientID: string
|
|
14
15
|
clientSecret: string
|
|
15
|
-
|
|
16
|
+
redirectPath: string
|
|
16
17
|
userInfoURL: string
|
|
17
|
-
|
|
18
|
+
tokenRedirectPath: string
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export interface AuthTokenProps {
|
|
21
22
|
req: NextRequest
|
|
22
|
-
frontendURL: string
|
|
23
23
|
redirectPath?: string
|
|
24
24
|
}
|
|
25
|
+
|
|
25
26
|
export interface AuthLogoutProps {
|
|
26
|
-
|
|
27
|
+
req: NextRequest
|
|
27
28
|
path?: string
|
|
28
|
-
frontendURL: string
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export default async function authLogin(props: AuthLoginProps): Promise<Response>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NextResponse } from 'next/server'
|
|
2
2
|
import type { AuthCallbackProps } from 'uibee/utils'
|
|
3
|
+
import { getDomain } from './getDomain'
|
|
3
4
|
|
|
4
5
|
type UserInfo = {
|
|
5
6
|
sub: string
|
|
@@ -14,10 +15,11 @@ export default async function authCallback({
|
|
|
14
15
|
tokenURL,
|
|
15
16
|
clientID,
|
|
16
17
|
clientSecret,
|
|
17
|
-
|
|
18
|
+
redirectPath,
|
|
18
19
|
userInfoURL,
|
|
19
|
-
|
|
20
|
+
tokenRedirectPath
|
|
20
21
|
}: AuthCallbackProps) {
|
|
22
|
+
const domain = getDomain(req)
|
|
21
23
|
const searchParams = new URL(req.url).searchParams
|
|
22
24
|
|
|
23
25
|
if (!searchParams) {
|
|
@@ -38,7 +40,7 @@ export default async function authCallback({
|
|
|
38
40
|
client_id: clientID,
|
|
39
41
|
client_secret: clientSecret,
|
|
40
42
|
code: code as string,
|
|
41
|
-
redirect_uri:
|
|
43
|
+
redirect_uri: `${domain}${redirectPath}`,
|
|
42
44
|
grant_type: 'authorization_code',
|
|
43
45
|
}).toString()
|
|
44
46
|
})
|
|
@@ -69,7 +71,7 @@ export default async function authCallback({
|
|
|
69
71
|
|
|
70
72
|
const userInfo = await userInfoResponse.json() as UserInfo
|
|
71
73
|
|
|
72
|
-
const redirectUrl = new URL(
|
|
74
|
+
const redirectUrl = new URL(`${domain}${tokenRedirectPath}`)
|
|
73
75
|
const params = new URLSearchParams({
|
|
74
76
|
id: userInfo.sub,
|
|
75
77
|
name: userInfo.name,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { NextRequest } from 'next/server'
|
|
2
|
+
|
|
3
|
+
export function getDomain(req: NextRequest): string {
|
|
4
|
+
const proto = req.headers.get('x-forwarded-proto') ?? new URL(req.url).protocol.replace(':', '')
|
|
5
|
+
const host = req.headers.get('x-forwarded-host') ?? req.headers.get('host') ?? new URL(req.url).host
|
|
6
|
+
return `${proto}://${host}`
|
|
7
|
+
}
|
package/src/utils/auth/login.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { NextResponse } from 'next/server'
|
|
2
2
|
import type { AuthLoginProps } from 'uibee/utils'
|
|
3
|
+
import { getDomain } from './getDomain'
|
|
3
4
|
|
|
4
|
-
export default async function AuthLogin({ clientID,
|
|
5
|
+
export default async function AuthLogin({ req, clientID, redirectPath, authURL }: AuthLoginProps) {
|
|
6
|
+
const domain = getDomain(req)
|
|
5
7
|
const state = Math.random().toString(36).substring(5)
|
|
6
8
|
const authQueryParams = new URLSearchParams({
|
|
7
9
|
client_id: clientID,
|
|
8
|
-
redirect_uri:
|
|
10
|
+
redirect_uri: `${domain}${redirectPath}`,
|
|
9
11
|
response_type: 'code',
|
|
10
12
|
scope: 'openid profile email',
|
|
11
13
|
state: state,
|
package/src/utils/auth/logout.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { NextResponse } from 'next/server'
|
|
2
2
|
import type { AuthLogoutProps } from 'uibee/utils'
|
|
3
|
+
import { getDomain } from './getDomain'
|
|
3
4
|
|
|
4
|
-
export default async function AuthLogout({
|
|
5
|
-
const
|
|
5
|
+
export default async function AuthLogout({ req, path }: AuthLogoutProps) {
|
|
6
|
+
const domain = getDomain(req)
|
|
7
|
+
const response = NextResponse.redirect(new URL(path || '/', domain))
|
|
6
8
|
|
|
7
9
|
const cookiesToRemove = [
|
|
8
10
|
'access_token',
|
package/src/utils/auth/token.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { NextResponse } from 'next/server'
|
|
2
2
|
import type { AuthTokenProps } from 'uibee/utils'
|
|
3
|
+
import { getDomain } from './getDomain'
|
|
3
4
|
|
|
4
|
-
export default async function AuthToken({ req,
|
|
5
|
+
export default async function AuthToken({ req, redirectPath }: AuthTokenProps) {
|
|
6
|
+
const domain = getDomain(req)
|
|
5
7
|
const url = new URL(req.url)
|
|
6
8
|
const token = url.searchParams.get('access_token')
|
|
7
9
|
const btg = url.searchParams.get('btg')
|
|
@@ -13,7 +15,7 @@ export default async function AuthToken({ req, frontendURL, redirectPath }: Auth
|
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
if (btg) {
|
|
16
|
-
return NextResponse.redirect(new URL(redirect,
|
|
18
|
+
return NextResponse.redirect(new URL(redirect, domain))
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
const accessToken = url.searchParams.get('access_token')!
|
|
@@ -23,7 +25,7 @@ export default async function AuthToken({ req, frontendURL, redirectPath }: Auth
|
|
|
23
25
|
const userEmail = url.searchParams.get('email')!
|
|
24
26
|
const userGroups = url.searchParams.get('groups')!
|
|
25
27
|
|
|
26
|
-
const response = NextResponse.redirect(new URL(redirect,
|
|
28
|
+
const response = NextResponse.redirect(new URL(redirect, domain))
|
|
27
29
|
response.cookies.set('access_token', accessToken)
|
|
28
30
|
response.cookies.set('user_id', userID)
|
|
29
31
|
response.cookies.set('user_name', username)
|