java - How to add a client using JDBC for ClientDetailsServiceConfigurer in Spring? -
i have in memory thing working follows:
@override public void configure(clientdetailsserviceconfigurer clients) throws exception { clients.inmemory() .withclient("clientapp") .authorizedgranttypes("password", "refresh_token") .authorities("user") .scopes("read", "write") .resourceids(resource_id) .secret("123456"); }
i use jdbc implementation. this, have created following tables (using mysql):
-- tables oauth token store 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 tinyint ); create table oauth_client_token ( token_id varchar(255), token blob, authentication_id varchar(255), user_name varchar(255), client_id varchar(255) ); create table oauth_access_token ( token_id varchar(255), token blob, authentication_id varchar(255), user_name varchar(255), client_id varchar(255), authentication blob, refresh_token varchar(255) ); create table oauth_refresh_token ( token_id varchar(255), token blob, authentication blob ); create table oauth_code ( code varchar(255), authentication blob );
do need manually add client in mysql tables?
i tried this:
clients.jdbc(datasource).withclient("clientapp") .authorizedgranttypes("password", "refresh_token") .authorities("user") .scopes("read", "write") .resourceids(resource_id) .secret("123456");
hoping spring insert correct things in tables, not seem that. why can further chain after jdbc()
?
please fallow steps:
-
put schema.sql inside resource folder detected springboot once start server. if don't use spring boot no worries import script mysql app client (phpmyadmin,heidisql,navicat..)
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) );
-
inject datasource, authenticationmanager,userdetailsservice inside othorizationserver
@autowired private myuserdetailsservice userdetailsservice; @inject private authenticationmanager authenticationmanager; @autowired private datasource datasource;
-
you need create 2 beans
@bean public jdbctokenstore tokenstore() { return new jdbctokenstore(datasource); } @bean protected authorizationcodeservices authorizationcodeservices() { return new jdbcauthorizationcodeservices(datasource); }
, please don't forget @configuration on top of authorizationserver class
- configure clients apps created in mysql database:
clients.jdbc(datasource).withclient("clientapp") .authorizedgranttypes("password", "refresh_token") .authorities("user") .scopes("read", "write") .resourceids(resource_id) .secret("123456");
you've done this.
-
the important thing ( , think forgot ..) is: configure endpoints authorizationserverendpointsconfigurer:
endpoints.userdetailsservice(userdetailsservice) .authorizationcodeservices(authorizationcodeservices()).authenticationmanager(this.authenticationmanager).tokenstore(tokenstore()).approvalstoredisabled();
and that's man , should work ;)
and feel free ask more... i'll happy
i have sent message tweeter !
Comments
Post a Comment