auth

Paddy 2015-07-15 Parent:8ecb60d29b0d

178:0a2c3d677161 Go to Latest

auth/sql/postgres_init.sql

Update to use a generic event emitter. Rather can creating a purpose-built event emitter for each and every event we need to emit (I'm looking at you, login verification event) which is _downright silly_, we're now using a generic event publisher that's based on saying "HEY A MODEL UPDATED". This means we need to change all our setup code in authd to use events.NewNSQPublisher or events.NewStdoutPublisher instead of our homegrown solutions. Which also means updating our config to take an events.Publisher instead of our LoginVerificationNotifier (blergh). Our Context also now uses an events.Publisher instead of a LoginVerificationNotifier. Party all around! We also replaced our SendLoginVerification helper method on Context with a SendModelEvent helper method on Context, which is just a light wrapper around events.PublishModelEvent. Of course, all this means we need to update our email_verification listener to listen to the correct channel (based on the model we want updates about) and filter down to a Created action or our new custom action for "the customer wants their verification resent", which I'm OK making a special case and not generic, because c'mon. But we had a subtle change to all our constants, some of which are unofficial constants now. I'm unsure how I feel about this. We also updated our email_verification listener so that we're unmarshalling to a custom loginEvent, which is just an events.Event that overwrites the Data property to be an auth.Login instance. This is to make sure we don't need to wrangle a map[string]interface{}, which is no fun. I'm also OK with special-casing like this, because it's 1) a tiny amount of code, 2) properly utilising composition, and 3) the only way I can think of to cleanly accomplish what I want. I also added a note about GetLogin's deficient handling of logins, namely that it doesn't recognise admins and return Verification codes to them, which would be a useful property for internal tools to take advantage of. Ah well. I updated the Profile and Login implementations so they're now event.Model instances, mainly by just exporting some strings from them through getters that will let us automatically build an Event from them. This lets us use the PublishModelEvent helper. I updated our CreateProfileHandler to properly mangle the login Verification property, and to fire off the ActionCreated events for the new Login and the new Profile. I updated our GetLoginHandler and UpdateLoginHandler to properly mangle the loginVerification property. God that's annoying. :-/ You'll note I didn't start publishing the events.ActionUpdated or events.ActionDeleted events for Profiles or Logins yet, and didn't bother publishing any events for literally any other type. That's because I'm a lazy piece of crap and will end up publishing them when I absolutely have to. Part of that is because if a channel isn't created/being read for a topic, the messages will just stack up in NSQ, and I don't want that. But mostly I'm lazy. Finally, I got to delete the entire profile_verification.go file, because we're no longer special-casing that. Hooray!

History
paddy@149 1 CREATE TABLE IF NOT EXISTS profiles (
paddy@149 2 id VARCHAR(36) PRIMARY KEY,
paddy@149 3 name VARCHAR(64) NOT NULL,
paddy@149 4 passphrase VARCHAR(64) NOT NULL,
paddy@149 5 iterations INTEGER NOT NULL,
paddy@149 6 salt VARCHAR(64) NOT NULL,
paddy@149 7 passphrase_scheme INTEGER NOT NULL,
paddy@149 8 compromised BOOLEAN NOT NULL,
paddy@149 9 locked_until TIMESTAMPTZ NOT NULL,
paddy@149 10 passphrase_reset VARCHAR(64) NOT NULL,
paddy@149 11 passphrase_reset_created TIMESTAMPTZ NOT NULL,
paddy@149 12 created TIMESTAMPTZ NOT NULL,
paddy@161 13 last_seen TIMESTAMPTZ NOT NULL
paddy@149 14 );
paddy@149 15
paddy@149 16 CREATE TABLE IF NOT EXISTS logins (
paddy@149 17 type VARCHAR(16) NOT NULL,
paddy@149 18 value VARCHAR(64) PRIMARY KEY,
paddy@149 19 profile_id VARCHAR(36) NOT NULL,
paddy@149 20 created TIMESTAMPTZ NOT NULL,
paddy@172 21 last_used TIMESTAMPTZ NOT NULL,
paddy@172 22 verification VARCHAR(36) NOT NULL,
paddy@172 23 verified BOOLEAN NOT NULL
paddy@149 24 );
paddy@151 25
paddy@151 26 CREATE TABLE IF NOT EXISTS clients (
paddy@151 27 id VARCHAR(36) PRIMARY KEY,
paddy@151 28 secret VARCHAR(64) NOT NULL,
paddy@151 29 owner_id VARCHAR(36) NOT NULL,
paddy@151 30 name VARCHAR(32) NOT NULL,
paddy@151 31 logo VARCHAR(512) NOT NULL,
paddy@151 32 website VARCHAR(140) NOT NULL,
paddy@151 33 type VARCHAR(16) NOT NULL,
paddy@151 34 deleted BOOLEAN NOT NULL
paddy@151 35 );
paddy@151 36
paddy@151 37 CREATE TABLE IF NOT EXISTS endpoints (
paddy@151 38 id VARCHAR(36) PRIMARY KEY,
paddy@151 39 client_id VARCHAR(36) NOT NULL,
paddy@151 40 uri VARCHAR(512) NOT NULL,
paddy@151 41 normalized_uri VARCHAR(512) NOT NULL,
paddy@151 42 added TIMESTAMPTZ NOT NULL
paddy@151 43 );
paddy@152 44
paddy@152 45 CREATE TABLE IF NOT EXISTS scopes (
paddy@152 46 id VARCHAR(64) PRIMARY KEY,
paddy@152 47 name VARCHAR(64) NOT NULL,
paddy@152 48 description TEXT NOT NULL
paddy@152 49 );
paddy@154 50
paddy@154 51 CREATE TABLE IF NOT EXISTS sessions (
paddy@154 52 id VARCHAR(72) PRIMARY KEY,
paddy@154 53 ip VARCHAR(32) NOT NULL,
paddy@154 54 user_agent TEXT NOT NULL,
paddy@154 55 profile_id VARCHAR(36) NOT NULL,
paddy@154 56 login VARCHAR(64) NOT NULL,
paddy@154 57 created TIMESTAMPTZ NOT NULL,
paddy@154 58 expires TIMESTAMPTZ NOT NULL,
paddy@154 59 active BOOLEAN NOT NULL,
paddy@154 60 csrftoken VARCHAR(72) NOT NULL
paddy@154 61 );
paddy@155 62
paddy@155 63 CREATE TABLE IF NOT EXISTS tokens (
paddy@168 64 access_token TEXT PRIMARY KEY,
paddy@155 65 refresh_token VARCHAR(36) UNIQUE NOT NULL,
paddy@155 66 created TIMESTAMPTZ NOT NULL,
paddy@155 67 created_from VARCHAR(128) NOT NULL,
paddy@155 68 expires_in INTEGER NOT NULL,
paddy@155 69 token_type VARCHAR(64) NOT NULL,
paddy@155 70 profile_id VARCHAR(36) NOT NULL,
paddy@155 71 client_id VARCHAR(36) NOT NULL,
paddy@155 72 revoked BOOLEAN NOT NULL,
paddy@163 73 scopes varchar(64)[] NOT NULL
paddy@155 74 );
paddy@156 75
paddy@156 76 CREATE TABLE IF NOT EXISTS authorization_codes (
paddy@156 77 code VARCHAR(36) PRIMARY KEY,
paddy@156 78 created TIMESTAMPTZ NOT NULL,
paddy@156 79 expires_in INTEGER NOT NULL,
paddy@156 80 client_id VARCHAR(36) NOT NULL,
paddy@156 81 redirect_uri TEXT NOT NULL,
paddy@156 82 state TEXT NOT NULL,
paddy@156 83 profile_id VARCHAR(36) NOT NULL,
paddy@163 84 used BOOLEAN NOT NULL,
paddy@163 85 scopes varchar(64)[] NOT NULL
paddy@156 86 );