The invention discloses a method for realizing resource service based on OAuth2 and a gateway, and relates to the technical field of information systems. Comprising the steps of 1, creating a resource manager component on a resource
server based on an OAuth 2.0 Resource
Server component and creating an API gateway component on the basis of SpringCloud Gateway, and 2, receiving an
access token carried by a
client through the API gateway component, verifying the validity of the
access token, checking the permission range of the
access token passing
verification, determining whether the
client has the right to access corresponding resources or not, and if the
client has the right to access corresponding resources, executing the step 3, and if the client has the right to access corresponding resources, executing the step 4. Step 3, receiving an access token carried by the client through the resource manager component, verifying the validity of the access token, checking the permission range of the access
token passing the
verification, determining whether the client has the right to access the corresponding resource or not, if yes, forwarding the request to the correct resource
server, and enabling the request to access the resource
server; and if the check is passed, providing the requested corresponding resources through the resource manager component.