In my Spring Boot application I have a single back-end application that exposes REST API.
I'm going to consume this API from different client applications(for example written in AngularJS).
Based on different OAuth2 clientId
I'd like to allow or restrict user access to different functionalities or data how it was described in my previous question Spring OAuth 2 + Spring Data Neo4j multi-tenancy
For example I have 3 different web domains:
example1.com
example2.com
example3.com
and for domain example1.com
I'd like to allow user login only with clientapp1
My current login url:
In my Spring OAuth2 server(with JWT tokens) I have configured multiple clients - clientapp1
, clientapp2
, clientapp3
@Configuration
@EnableAuthorizationServer
protected static class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
// @formatter:off
clients
.inMemory()
.withClient("clientapp1")
.authorizedGrantTypes("password","refresh_token")
.authorities("ROLE_CLIENT")
.scopes("read", "write")
.resourceIds(RESOURCE_ID)
.secret("123456")
.and()
.withClient("clientapp2")
.authorizedGrantTypes("implicit")
.scopes("read", "write")
.autoApprove(true)
.and()
.withClient("clientapp3")
.authorizedGrantTypes("password", "authorization_code", "refresh_token", "implicit")
.authorities("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT")
.scopes("read", "write", "trust")
.accessTokenValiditySeconds(60);
// @formatter:on
}
}
The issue is that right now any user in the system can login into the applications with any clientId
and thus can use for example domain3.com
with clientapp1
I need the following behavior:
REST API calls from domain1.com
must be only allowed with OAuth2 JWT token only with clientapp1
inside, for domain2.com
only with clientapp2
and so on.
How to configure my application in order to be able only login user with a correct clientId
for appropriate domain ?
Is it safe to store and directly use clientId
value on client side(in user browser) ?
Also, if my approach is wrong - please suggest how to correctly implement multi-tenancy with OAuth2.