First commit

This commit is contained in:
2026-01-15 14:12:41 +09:00
commit b28238cfd3
15 changed files with 1949 additions and 0 deletions

46
sso-demo/models/user.js Normal file
View File

@@ -0,0 +1,46 @@
// In-memory user store for demonstration purposes
// In a real application, this would be a database model (e.g., Sequelize, Mongoose)
const users = [];
let nextId = 1;
/**
* Finds a user by their SSO subject ID.
* @param {string} ssoSub - The SSO subject ID.
* @returns {Promise<object|null>} The user object or null if not found.
*/
async function findBySsoSub(ssoSub) {
return users.find(user => user.sso_sub === ssoSub) || null;
}
/**
* Finds a user by their internal ID.
* @param {number} id - The user's internal ID.
* @returns {Promise<object|null>} The user object or null if not found.
*/
async function findById(id) {
return users.find(user => user.id === id) || null;
}
/**
* Creates a new user.
* @param {object} userData - The user data.
* @param {string} userData.sso_sub - The SSO subject ID.
* @returns {Promise<object>} The newly created user object.
*/
async function createUser({ sso_sub }) {
const newUser = {
id: nextId++,
sso_sub: sso_sub,
// In a real app, you might get a username/email from the JWT or prompt the user
username: `user_${sso_sub.substring(0, 5)}`
};
users.push(newUser);
return newUser;
}
module.exports = {
findBySsoSub,
findById,
createUser
};