Skip to content

Add example for Authorization Code grant. #9

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

Merged
merged 12 commits into from
Jul 30, 2025
Prev Previous commit
Next Next commit
PR comments.
  • Loading branch information
shrihari-prakash committed Jul 9, 2025
commit 7adf469fab62305e32add78a59f9d0389baf3822
4 changes: 4 additions & 0 deletions authorization-code/client/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
AUTH_SERVER=http://localhost:8080
CLIENT_ID=testclient
CLIENT_SECRET=testsecret
REDIRECT_URI=http://localhost:3000/callback
9 changes: 4 additions & 5 deletions authorization-code/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ app.set("view engine", "ejs");
app.set("views", "./views");
app.use(express.static("public"));

const authServer = process.env.AUTH_SERVER || "http://localhost:8080";
const clientId = process.env.CLIENT_ID || "testclient";
const clientSecret = process.env.CLIENT_SECRET || "testsecret";
const redirectUri =
process.env.REDIRECT_URI || "http://localhost:3000/callback";
const authServer = process.env.AUTH_SERVER;
const clientId = process.env.CLIENT_ID;
const clientSecret = process.env.CLIENT_SECRET;
const redirectUri = process.env.REDIRECT_URI;

function generateState() {
return crypto.randomBytes(16).toString("hex");
Expand Down
6 changes: 6 additions & 0 deletions authorization-code/provider/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CLIENT_ID=testclient
CLIENT_SECRET=testsecret
REDIRECT_URI=http://localhost:3000/callback
USER_ID=user1
USERNAME=demo
PASSWORD=demo
12 changes: 6 additions & 6 deletions authorization-code/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ app.set("view engine", "ejs");
app.set("views", "./views");

db.saveClient({
id: process.env.CLIENT_ID || "testclient",
secret: process.env.CLIENT_SECRET || "testsecret",
id: process.env.CLIENT_ID,
secret: process.env.CLIENT_SECRET,
grants: ["authorization_code", "refresh_token"],
redirectUris: [process.env.REDIRECT_URI || "http://localhost:3000/callback"],
redirectUris: [process.env.REDIRECT_URI],
});

db.saveUser({
id: process.env.USER_ID || "user1",
username: process.env.USERNAME || "demo",
password: process.env.PASSWORD || "demo",
id: process.env.USER_ID,
username: process.env.USERNAME,
password: process.env.PASSWORD,
});

app.use(bodyParser.json());
Expand Down