SpringBootSecurity learning (25) separating front and rear ends token version of the relay OAuth2.0

Increase in Eureka

Projects previously authorized services and resources are two separate services, such check_token address resources in the service of the write address are dead:

file

Here we add the eureka, so that you can directly use the service name. Build eureka services are not discussed, in the service plus eureka only need to change two places, it is to add and modify the configuration dependent:

file

Increase the allocation is as follows:

file

Then you can put the resources in the service of fixed ip service name was changed to:

file

Relay token increase

After obtaining a token from the authorization service, direct access to a resource service is no problem, but if the resource service calls went to other resources services, the question arises, is the token can not be automatically passed down. To achieve the token relay we need to write an interceptor, the token header into the request.

First increase feign components in the service:

file

Increase in notes @EnableFeignClients:

file

Note that the above dependence and notes the caller and callee will also increase. Then write an interface to the called party:

file

Use feign call the caller:

file

Then write a test interface in the caller:

file

Now apply directly for a token, and then access the caller test interface, the following 401 error:

file

The following increase in the caller an interceptor, a token increase in the header:

file

test

Directly apply the following token, access to the caller's test interface, you can see the results of token relay:

file

Code Address: https: //gitee.com/blueses/spring-boot-security 30 31 32 33

This article from the blog article multiple platforms OpenWrite release!

Guess you like

Origin www.cnblogs.com/guos/p/11688103.html