Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Peter/fix aud #7

Merged
merged 2 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from "react";

export function useKindeAuth(): State;
export function KindeProvider({
export declare function useKindeAuth(): State;
export declare function KindeProvider({
children,
}: {
children: any;
}): React.Provider<State>;
export function handleAuth(): any;
export declare function handleAuth(): any;
export type User = {
id: string;
name: string | null;
Expand Down
12 changes: 1 addition & 11 deletions src/handlers/callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ export const callback = async (req, res) => {
const accessTokenHeader = jwt_decode(data.access_token, { header: true });
const accessTokenPayload = jwt_decode(data.access_token);

let isAudienceValid = true;

if (config.audience != undefined) {
isAudienceValid = accessTokenPayload.aud == config.audience;
}

let isAudienceValid = accessTokenPayload.aud == config.audience;
if (
accessTokenPayload.iss == config.issuerURL &&
accessTokenHeader.alg == "RS256" &&
Expand All @@ -55,11 +50,6 @@ export const callback = async (req, res) => {
);
} else {
console.error("One or more of the claims were not verified.");
const logoutURL = new URL(
config.issuerURL + config.issuerRoutes.logout
);
logoutURL.searchParams.set("redirect", config.postLogoutRedirectURL);
res.redirect(logoutURL.href);
}
} catch (err) {
console.error(err);
Expand Down
5 changes: 4 additions & 1 deletion src/handlers/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const login = async (req, res) => {
code_challenge_method: config.codeChallengeMethod,
state,
start_page: "login",
audience: config.audience,
};

if (org_code) {
Expand All @@ -30,6 +29,10 @@ export const login = async (req, res) => {
searchParams.org_name = org_name;
}

if (config.audience) {
searchParams.audience = config.audience;
}

loginURL.search = new URLSearchParams(searchParams);

res.redirect(loginURL.href);
Expand Down
4 changes: 3 additions & 1 deletion src/handlers/me.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export const me = async (req, res) => {
console.log(err);
}
} else {
res.status(401).send("Unauthorized");
res.status(401).send({
message: "Unauthorized",
});
}
};
5 changes: 4 additions & 1 deletion src/handlers/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const register = async (req, res) => {
code_challenge_method: config.codeChallengeMethod,
state,
start_page: "registration",
audience: config.audience,
};

if (org_code) {
Expand All @@ -30,6 +29,10 @@ export const register = async (req, res) => {
searchParams.org_name = org_name;
}

if (config.audience) {
searchParams.audience = config.audience;
}

registerURL.search = new URLSearchParams(searchParams);

res.redirect(registerURL.href);
Expand Down