Skip to content

Commit

Permalink
handleAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
peterphanouvong committed May 19, 2022
1 parent 3d600ea commit 87f52c6
Show file tree
Hide file tree
Showing 11 changed files with 704 additions and 3,353 deletions.
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.

4,006 changes: 654 additions & 3,352 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@
"peerDependencies": {
"react": "^18.1.0",
"react-dom": "^18.1.0"
},
"dependencies": {
"cookie": "^0.5.0",
"crypto": "^1.0.1"
}
}
5 changes: 5 additions & 0 deletions src/client/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { setupChallenge } from "../utils/setupChallenge";

export const createClient = () => {
console.log(createClient);
};
1 change: 1 addition & 0 deletions src/config/sessionPrefix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const SESSION_PREFIX = "pkce-verifier";
10 changes: 10 additions & 0 deletions src/handlers/handleAuth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { login } from "./login";

export default function handler(req, res) {
const { kindeAuth: route } = req.query;

switch (route) {
case "login":
return login(req, res);
}
}
1 change: 1 addition & 0 deletions src/handlers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as handleAuth } from "./handleAuth";
8 changes: 8 additions & 0 deletions src/handlers/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { setupChallenge } from "../utils/setupChallenge";

export const login = (req, res) => {
// setupChallenge();
console.log("log in");
console.log("req", req);
console.log("res", res);
};
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { KindeProvider, AuthContext, useAuth } from "./frontend/index";
export { handleAuth } from "./handlers/index";
3 changes: 3 additions & 0 deletions src/utils/randomString.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const crypto = require("crypto");

export const randomString = () => crypto.randomBytes(28).toString("hex");
16 changes: 16 additions & 0 deletions src/utils/setupChallenge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { randomString } from "./randomString";
import { SESSION_PREFIX } from "../config/sessionPrefix";
var cookie = require("cookie");

export const setupChallenge = () => {
const state = randomString();
const code_verifier = randomString(); // the secret
// Hash and base64-urlencode the secret to use as the challenge
const code_challenge = "await pkceChallengeFromVerifier(code_verifier)";

cookie.parse(`${SESSION_PREFIX}-${state}`, code_verifier);

// Build and encode the authorisation request url
const url = new URL(config.authorization_endpoint);
return { state, code_challenge, url };
};

0 comments on commit 87f52c6

Please sign in to comment.