Skip to content

Instantly share code, notes, and snippets.

@fernandomantoan
Created September 23, 2014 18:05
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
  • Save fernandomantoan/3ff4b90d7e9eae4a5d1e to your computer and use it in GitHub Desktop.
Save fernandomantoan/3ff4b90d7e9eae4a5d1e to your computer and use it in GitHub Desktop.
Schema for PostgreSQL to use with JdbcTokenStore (Spring Security OAuth2)
create table oauth_client_details (
client_id VARCHAR(256) PRIMARY KEY,
resource_ids VARCHAR(256),
client_secret VARCHAR(256),
scope VARCHAR(256),
authorized_grant_types VARCHAR(256),
web_server_redirect_uri VARCHAR(256),
authorities VARCHAR(256),
access_token_validity INTEGER,
refresh_token_validity INTEGER,
additional_information VARCHAR(4096),
autoapprove VARCHAR(256)
);
create table oauth_client_token (
token_id VARCHAR(256),
token bytea,
authentication_id VARCHAR(256),
user_name VARCHAR(256),
client_id VARCHAR(256)
);
create table oauth_access_token (
token_id VARCHAR(256),
token bytea,
authentication_id VARCHAR(256),
user_name VARCHAR(256),
client_id VARCHAR(256),
authentication bytea,
refresh_token VARCHAR(256)
);
create table oauth_refresh_token (
token_id VARCHAR(256),
token bytea,
authentication bytea
);
create table oauth_code (
code VARCHAR(256), authentication bytea
);
create table oauth_approvals (
userId VARCHAR(256),
clientId VARCHAR(256),
scope VARCHAR(256),
status VARCHAR(10),
expiresAt TIMESTAMP,
lastModifiedAt TIMESTAMP
);
@Dbuggerx
Copy link

Thanks for this, really helped me out!

@pablobaldez
Copy link

should I use pk's and indexes?

@mateusz-lisik
Copy link

Awesome! Thanks!

@mihaita-tinta
Copy link

Thanks!

@chrylis
Copy link

chrylis commented Sep 29, 2016

Definitely could use constraints, both PKs and a FK from oauth_access_token.refresh_token to oauth_refresh_token.token_id.

@rokerTT
Copy link

rokerTT commented Feb 13, 2017

Thank you! It helped me!

@brijanresilinc
Copy link

brijanresilinc commented Feb 20, 2017

hi can I pass this user token to postgres so that it can it can fill data like
created by,lastmodifiedby

@zcmgyu
Copy link

zcmgyu commented Oct 11, 2017

Save my day. <3

@quanblackhat
Copy link

Hi Fernando, I has some issue, can you support me.
My project only using Grant Type <client_credentials>. So I think I can not using some tables.
So what would I keep from the ones above?
Thanks you.

@alkawero
Copy link

thank you. this help me alot

@PeterInfinity
Copy link

nice

@andrelsf
Copy link

\o_ Very nice

@mahmood-alashqar
Copy link

thank you man

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment