- created identity_provider_user table

- updated exchange to use new table
pull/491/head
Jeffrey 2 years ago
parent 827e51a590
commit 53850201a1

@ -106,7 +106,21 @@ module.exports = {
updatedAt: now, updatedAt: now,
}; };
const user = await User.findOrCreate({ username: userInfo.preferred_username }, newUser); const identityProviderUser = await IdentityProviderUser.findOne({
where: {
issuer: oidcUser.iss,
sub: oidcUser.sub,
},
}).populate('userId');
let user = identityProviderUser ? identityProviderUser.userId : {};
if (!identityProviderUser) {
user = await User.create(newUser).fetch();
await IdentityProviderUser.create({
issuer: oidcUser.iss,
sub: oidcUser.sub,
userId: user.id,
});
}
const controlledFields = ['email', 'password', 'isAdmin', 'name', 'username']; const controlledFields = ['email', 'password', 'isAdmin', 'name', 'username'];
const updateFields = {}; const updateFields = {};

@ -1,5 +1,5 @@
/** /**
* IdentityProviderUser.js * ProjectManager.js
* *
* @description :: A model definition represents a database table/collection. * @description :: A model definition represents a database table/collection.
* @docs :: https://sailsjs.com/docs/concepts/models-and-orm/models * @docs :: https://sailsjs.com/docs/concepts/models-and-orm/models
@ -7,20 +7,19 @@
module.exports = { module.exports = {
attributes: { attributes: {
// ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
// ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝
issuer: { issuer: {
type: 'issuer', type: 'string',
isNotEmptyString: true, isNotEmptyString: true,
required: true, allowNull: true,
}, },
sub: { sub: {
type: 'sub', type: 'string',
required: true,
isNotEmptyString: true, isNotEmptyString: true,
allowNull: true,
}, },
// ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
// ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝
// ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗ // ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗
// ║╣ ║║║╠╩╗║╣ ║║╚═╗ // ║╣ ║║║╠╩╗║╣ ║║╚═╗

@ -97,6 +97,10 @@ module.exports = {
via: 'userId', via: 'userId',
through: 'CardMembership', through: 'CardMembership',
}, },
identityProviders: {
collection: 'IdentityProviderUser',
via: 'userId',
},
}, },
tableName: 'user_account', tableName: 'user_account',

@ -0,0 +1,22 @@
module.exports.up = (knex) =>
knex.schema.createTable('identity_provider_user', (table) => {
/* Columns */
table.bigInteger('id').primary().defaultTo(knex.raw('next_id()'));
table
.bigInteger('user_id')
.notNullable()
.references('id')
.inTable('user_account')
.onDelete('CASCADE');
table.text('issuer').notNullable();
table.text('sub').notNullable();
/* Indexes */
table.index('user_id');
});
module.exports.down = (knex) => knex.schema.dropTable('identity_provider_user');
Loading…
Cancel
Save