4

The Spring OAuth2 uses the next database schema by this tutorial:

drop table if exists oauth_client_details;
create table oauth_client_details (
  client_id VARCHAR(255) PRIMARY KEY,
  resource_ids VARCHAR(255),
  client_secret VARCHAR(255),
  scope VARCHAR(255),
  authorized_grant_types VARCHAR(255),
  web_server_redirect_uri VARCHAR(255),
  authorities VARCHAR(255),
  access_token_validity INTEGER,
  refresh_token_validity INTEGER,
  additional_information VARCHAR(4096),
  autoapprove VARCHAR(255)
);

drop table if exists oauth_client_token;
create table oauth_client_token (
  token_id VARCHAR(255),
  token LONG VARBINARY,
  authentication_id VARCHAR(255) PRIMARY KEY,
  user_name VARCHAR(255),
  client_id VARCHAR(255)
);

drop table if exists oauth_access_token;
create table oauth_access_token (
  token_id VARCHAR(255),
  token LONG VARBINARY,
  authentication_id VARCHAR(255) PRIMARY KEY,
  user_name VARCHAR(255),
  client_id VARCHAR(255),
  authentication LONG VARBINARY,
  refresh_token VARCHAR(255)
);

drop table if exists oauth_refresh_token;
create table oauth_refresh_token (
  token_id VARCHAR(255),
  token LONG VARBINARY,
  authentication LONG VARBINARY
);

drop table if exists oauth_code;
create table oauth_code (
  code VARCHAR(255), authentication LONG VARBINARY
);

drop table if exists oauth_approvals;
create table oauth_approvals (
    userId VARCHAR(255),
    clientId VARCHAR(255),
    scope VARCHAR(255),
    status VARCHAR(10),
    expiresAt TIMESTAMP,
    lastModifiedAt TIMESTAMP
);

drop table if exists ClientDetails;
create table ClientDetails (
  appId VARCHAR(255) PRIMARY KEY,
  resourceIds VARCHAR(255),
  appSecret VARCHAR(255),
  scope VARCHAR(255),
  grantTypes VARCHAR(255),
  redirectUrl VARCHAR(255),
  authorities VARCHAR(255),
  access_token_validity INTEGER,
  refresh_token_validity INTEGER,
  additionalInformation VARCHAR(4096),
  autoApproveScopes VARCHAR(255)
);

I have few tables are generated by JPA... I can't get how can I add custom fields to store information about my site users? And how to link my JPA-generated tables with these tables? (how to run JPA after this script only? And what table and field can I use like a foreign key for my JPA tables?)
P.S. I am noobie in Spring OAuth2 and trying to get it by tutorials but can't find information how to link it with JPA tables...
ADDED I need to store information like (email, first_name, last_name, hash, salt, birthdate and etc) and I need to JPA could get this information to create my User class and store it back.
My user table:

@Entity
@Table(name = UserKeys.TABLE_NAME, catalog = Database.NAME,
        uniqueConstraints = {
            @UniqueConstraint(columnNames = UserKeys.EMAIL)
        }
)
public class User implements Serializable {

    private static final long serialVersionUID = -8190974017668449062L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = UserKeys.ID, nullable = false)
    @Type(type="pg-uuid")
    private UUID mId; // How to change it to link with OAuth2 users
    @Column(name = UserKeys.FIRST_NAME, nullable = false)
    private String mFirstName;
    @Column(name = UserKeys.LAST_NAME, nullable = false)
    private String mLastName;
    @Column(name = UserKeys.EMAIL, nullable = false)
    private String mEmail;
    @Column(name = UserKeys.BIRTHDATE, nullable = false)
    @Type(type="date")
    private Date mBirthdate;
    @Column(name = UserKeys.SEX, nullable = false)
    @Enumerated(EnumType.STRING)
    private Sex mSex;
    @Column(name = UserKeys.ROLE, nullable = false)
    @Enumerated(EnumType.STRING)
    private Role mRole;
    @Column(name = UserKeys.HASH, nullable = false, length = 32)
    private String mHash;
    @Column(name = UserKeys.SALT, nullable = false, length = 20)
    private String mSalt;
}
Denis Sologub
  • 7,277
  • 11
  • 56
  • 123

0 Answers0