I not really understand of concept how exactly I have to link front with back in clue oauth2. I see few library in spring witch oauht2-client and oauth2-resource-server. As client use ionic of application which get token from google and then send this **id token ** to my backend spring boot application which use oauth2-resource-server and I validate this beawer token and return data from api resource.
But I want create a local user (registration user) but I not really anderstand where and main how a must create this local user.
Now it's just validate id token from google and return info from api resource.
Which right way use oauth2? I think It's will be like:
- User approve google oauth2
- Front send request with id Token
- Backend check if user already exist (if not create from id token info)
- Backend create access token and return to front
- Front get info from resource server with access token
Can you explain how I must do that right?
My code on spring boot
security.conf
SecurityFilterChain filterChain(HttpSecurity http) throws Exception { return http .authorizeHttpRequests() .requestMatchers("/open").permitAll() .anyRequest().authenticated() .and() .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) .and() .oauth2ResourceServer().jwt() .and().and() .cors().and().csrf().disable() .build(); }
application.aml
spring: security: oauth2: resourceserver: jwt: issuer-uri: accounts.google.com jwk-set-uri: https://www.googleapis.com/oauth2/v3/certs
build.gradle
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-web'