auth

Paddy 2015-04-19 Parent:849f3820b164 Child:581c60f8dd23

163:73e12d5a1124 Go to Latest

auth/sql/postgres_init.sql

Use postgres arrays for scope associations. Use the new pqarrays library I wrote to store Scope associations for Tokens and AuthorizationCodes, instead of using our hacky and abstraction-breaking many-to-many code. We also created the authStore.deleteAuthorizationCodesByProfileID method, to clear out the AuthorizationCodes that belong to a Profile (used when the Profile is deleted). So we added the implementation for memstore and for our postgres store. Call Context.DeleteAuthorizationCodesByProfileID when deleting a Profile to clean up after it. Rename sortedScopes to Scopes, which we use pqarrays.StringArray's methods on to fulfill the sql.Scanner and driver.Valuer interfaces. This lets us store Scopes in postgres arrays. Create a stringsToScopes helper function that creates Scope objects, with their IDs filled by the strings specified. Update our GrantType.Validate function signature to return Scopes instead of []string. Create a Scopes.Strings() helper method that returns a []string of the IDs of the Scopes. Update our SQL init file to use the new postgres array definition, instead of the many-to-many definition.

History
     1.1 --- a/sql/postgres_init.sql	Sat Apr 11 19:07:26 2015 -0400
     1.2 +++ b/sql/postgres_init.sql	Sun Apr 19 23:18:26 2015 -0400
     1.3 @@ -68,13 +68,8 @@
     1.4  	profile_id VARCHAR(36) NOT NULL,
     1.5  	client_id VARCHAR(36) NOT NULL,
     1.6  	revoked BOOLEAN NOT NULL,
     1.7 -	refresh_revoked BOOLEAN NOT NULL
     1.8 -);
     1.9 -
    1.10 -CREATE TABLE IF NOT EXISTS scopes_tokens (
    1.11 -	token VARCHAR(36) NOT NULL,
    1.12 -	scope VARCHAR(64) NOT NULL,
    1.13 -	PRIMARY KEY(token, scope)
    1.14 +	refresh_revoked BOOLEAN NOT NULL,
    1.15 +	scopes varchar(64)[] NOT NULL
    1.16  );
    1.17  
    1.18  CREATE TABLE IF NOT EXISTS authorization_codes (
    1.19 @@ -85,11 +80,6 @@
    1.20  	redirect_uri TEXT NOT NULL,
    1.21  	state TEXT NOT NULL,
    1.22  	profile_id VARCHAR(36) NOT NULL,
    1.23 -	used BOOLEAN NOT NULL
    1.24 +	used BOOLEAN NOT NULL,
    1.25 +	scopes varchar(64)[] NOT NULL
    1.26  );
    1.27 -
    1.28 -CREATE TABLE IF NOT EXISTS authorization_codes_scopes (
    1.29 -	code VARCHAR(36) NOT NULL,
    1.30 -	scope VARCHAR(64) NOT NULL,
    1.31 -	PRIMARY KEY(code, scope)
    1.32 -);