{"id":21981,"date":"2023-05-27T09:13:23","date_gmt":"2023-05-27T02:13:23","guid":{"rendered":"https:\/\/huongdanjava.com\/?p=21981"},"modified":"2023-05-27T09:13:23","modified_gmt":"2023-05-27T02:13:23","slug":"working-with-authorization-server-using-spring-security-oauth2-client","status":"publish","type":"post","link":"https:\/\/huongdanjava.com\/working-with-authorization-server-using-spring-security-oauth2-client.html","title":{"rendered":"Working with Authorization Server using Spring Security OAuth2 Client"},"content":{"rendered":"<p>In the article <a href=\"https:\/\/huongdanjava.com\/implement-oauth-resource-server-using-spring-security-oauth2-resource-server.html\" target=\"_blank\" rel=\"noopener\">Implement OAuth Resource Server using Spring Security OAuth2 Resource Server<\/a>, I showed you how to protect resources managed by Resource Server using an access token issued by Authorization Server. In the example of this article <a href=\"https:\/\/huongdanjava.com\/implement-oauth-resource-server-using-spring-security-oauth2-resource-server.html\" target=\"_blank\" rel=\"noopener\">Implement OAuth Resource Server using Spring Security OAuth2 Resource Server<\/a>, I use Postman to act as a Client Application, also known as an OAuth2 Client, requesting resources. To implement an OAuth2 Client using code, you can use <a href=\"https:\/\/docs.spring.io\/spring-security\/reference\/reactive\/oauth2\/client\/index.html\" target=\"_blank\" rel=\"noopener\">the Spring Security OAuth2 Client library<\/a>. How is it in detail? Let&#8217;s find out together in this tutorial!<\/p>\n<p>As an example, I will reuse the Resource Server and Authorization Server that I built in the article\u00a0<a href=\"https:\/\/huongdanjava.com\/implement-oauth-resource-server-using-spring-security-oauth2-resource-server.html\" target=\"_blank\" rel=\"noopener\">Implement OAuth Resource Server using Spring Security OAuth2 Resource Server<\/a>, guys!<\/p>\n<p>Now I will create another Spring Boot application that acts as an OAuth2 Client, and expose an API for the user to pass the &#8220;name&#8221;, this API will return the text &#8220;Hello Khanh&#8221; for example:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-21983 aligncenter\" src=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2023\/05\/working-with-authorization-server-using-spring-security-oauth2-client-1.png\" alt=\"\" width=\"700\" height=\"856\" \/><\/p>\n<p>We will use Spring Security, Spring Web, and OAuth2 Client dependency as you can see!<\/p>\n<p>Result:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-21984 aligncenter\" src=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2023\/05\/working-with-authorization-server-using-spring-security-oauth2-client-2.png\" alt=\"\" width=\"700\" height=\"400\" \/><\/p>\n<p>I will run this application using port 8082:<\/p>\n<pre class=\"lang:java decode:true \">server.port=8082<\/pre>\n<p>I will create a new RESTful API for the user to pass &#8220;name&#8221; information as follows:<\/p>\n<pre class=\"lang:java decode:true \">package com.huongdanjava.springsecurity;\r\n\r\nimport org.springframework.web.bind.annotation.GetMapping;\r\nimport org.springframework.web.bind.annotation.RequestParam;\r\nimport org.springframework.web.bind.annotation.RestController;\r\n\r\n@RestController\r\npublic class HelloController {\r\n\r\n  @GetMapping(\"\/hello\")\r\n  public String hello(@RequestParam String name) {\r\n    String responseFromResourceServer = \"\";\r\n    return responseFromResourceServer + name;\r\n  }\r\n\r\n}\r\n<\/pre>\n<p>For this request, I don&#8217;t need the user to authenticate to make calls, so I will configure the Spring Security permit all as follows:<\/p>\n<pre class=\"lang:java decode:true \">package com.huongdanjava.springsecurity;\r\n\r\nimport org.springframework.context.annotation.Bean;\r\nimport org.springframework.context.annotation.Configuration;\r\nimport org.springframework.security.config.annotation.web.builders.HttpSecurity;\r\nimport org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;\r\nimport org.springframework.security.web.SecurityFilterChain;\r\n\r\n@Configuration\r\n@EnableWebSecurity\r\npublic class SpringSecurityConfiguration {\r\n\r\n  @Bean\r\n  SecurityFilterChain filterChain(HttpSecurity http) throws Exception {\r\n    \/\/ @formatter:off\r\n    http\r\n        .authorizeHttpRequests((authz) -&gt; authz\r\n            .anyRequest().permitAll()\r\n        );\r\n    \/\/ @formatter:on\r\n\r\n    return http.build();\r\n  }\r\n\r\n}\r\n<\/pre>\n<p><strong>When the user requests this API, we will get the access token from the Authorization Server first. Then, will request to resource &#8220;\/hello&#8221; of the Resource Server. The response returned from the Resource Server will be added with the name that the user transmits, to return to the user.<\/strong><\/p>\n<p><strong>OK, now we will work with the Authorization Server first.<\/strong><\/p>\n<p>Spring Security OAuth2 Client library provides us with an interface called OAuth2AuthorizedClientManager to manage information of all clients that have been authorized with Authorization Server. We will initialize the bean for the object of this OAuth2AuthorizedClientManager class first.<\/p>\n<p>There are two implementations for this interface, DefaultOAuth2AuthorizedClientManager and AuthorizedClientServiceOAuth2AuthorizedClientManager:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-21985 aligncenter\" src=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2023\/05\/working-with-authorization-server-using-spring-security-oauth2-client-3.png\" alt=\"\" width=\"700\" height=\"544\" \/><\/p>\n<p>The DefaultOAuth2AuthorizedClientManager class is used in the context of the web application, and the AuthorizedClientServiceOAuth2AuthorizedClientManager is used in the outside context of the web application like a scheduled\/background thread! We will use the DefaultOAuth2AuthorizedClientManager implementation for this example.<\/p>\n<p>I will create a new ApplicationConfiguration class to initialize the bean for the OAuth2AuthorizedClientManager class as follows:<\/p>\n<pre class=\"lang:java mark:15-35 decode:true \">package com.huongdanjava.springsecurity;\r\n\r\nimport org.springframework.context.annotation.Bean;\r\nimport org.springframework.context.annotation.Configuration;\r\nimport org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager;\r\nimport org.springframework.security.oauth2.client.OAuth2AuthorizedClientProvider;\r\nimport org.springframework.security.oauth2.client.OAuth2AuthorizedClientProviderBuilder;\r\nimport org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;\r\nimport org.springframework.security.oauth2.client.web.DefaultOAuth2AuthorizedClientManager;\r\nimport org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository;\r\n\r\n@Configuration\r\npublic class AppConfiguration {\r\n\r\n  @Bean\r\n  OAuth2AuthorizedClientManager oauth2AuthorizedClientManager(\r\n      ClientRegistrationRepository clientRegistrationRepository,\r\n      OAuth2AuthorizedClientRepository oauth2AuthorizedClientRepository) {\r\n\r\n    \/\/ @formatter:off\r\n    OAuth2AuthorizedClientProvider authorizedClientProvider =\r\n        OAuth2AuthorizedClientProviderBuilder.builder()\r\n            .authorizationCode()\r\n            .refreshToken()\r\n            .clientCredentials()\r\n            .build();\r\n    \/\/ @formatter:on\r\n\r\n    DefaultOAuth2AuthorizedClientManager authorizedClientManager =\r\n        new DefaultOAuth2AuthorizedClientManager(clientRegistrationRepository,\r\n            oauth2AuthorizedClientRepository);\r\n    authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider);\r\n\r\n    return authorizedClientManager;\r\n  }\r\n\r\n}\r\n<\/pre>\n<p>To initialize the object for the DefaultOAuth2AuthorizedClientManager class, we need to use the objects of two other classes, as you can see, ClientRegistrationRepository and OAuth2AuthorizedClientRepository. The ClientRegistrationRepository class will contain the client information we will use and has been declared in the Authorization Server, and the OAuth2AuthorizedClientRepository will contain information about the authorized clients with the Authorization Server.<\/p>\n<p>Another class, OAuth2AuthorizedClientProvider, will be responsible for authorizing or re-authorizing if our client has not been authorized. We will initialize this object with the grant types we need to authorize or re-authorize.<\/p>\n<p>For our example, we need to declare client information that we will use, as in Authorization Server as follows:<\/p>\n<pre class=\"lang:java decode:true\">@Bean\r\nClientRegistrationRepository clientRegistrationRepository() {\r\n  \/\/ @formatter:off\r\n  ClientRegistration clientRegistration1 = ClientRegistration.withRegistrationId(\"huongdanjava1\")\r\n      .clientId(\"huongdanjava1\")\r\n      .clientSecret(\"{noop}123\")\r\n      .clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_POST)\r\n      .authorizationGrantType(AuthorizationGrantType.CLIENT_CREDENTIALS)\r\n      .tokenUri(\"http:\/\/localhost:8080\/oauth2\/token\")\r\n      .scope(\"access-hello\")\r\n      .build();\r\n  \/\/ @formatter:on\r\n\r\n  return new InMemoryClientRegistrationRepository(clientRegistration1);\r\n}<\/pre>\n<p>You need to configure Uri to get the access token from the Authorization Server for this client!<\/p>\n<p><strong>To request the Resource Server with the resource we want, you can use <a href=\"https:\/\/huongdanjava.com\/consume-reactive-web-service-using-webclient-of-spring-webflux.html\" target=\"_blank\" rel=\"noopener\">the WebClient class<\/a>.<\/strong><\/p>\n<p>You need to declare more WebFlux dependency as follows:<\/p>\n<pre class=\"lang:xhtml decode:true \">&lt;dependency&gt;\r\n  &lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n  &lt;artifactId&gt;spring-webflux&lt;\/artifactId&gt;\r\n&lt;\/dependency&gt;<\/pre>\n<p>The Spring Security OAuth2 Client library provides us with a class called ServletOAuth2AuthorizedClientExchangeFilterFunction that can be integrated with the WebClient class so that requests to the Resource Server using WebClient always include the access token of the authorized client. We can initialize the bean for the WebClient class to integrate with the ServletOAuth2AuthorizedClientExchangeFilterFunction class as follows:<\/p>\n<pre class=\"lang:java decode:true\">@Bean\r\nWebClient webClient(OAuth2AuthorizedClientManager oauth2AuthorizedClientManager) {\r\n  ServletOAuth2AuthorizedClientExchangeFilterFunction oauth2Client =\r\n      new ServletOAuth2AuthorizedClientExchangeFilterFunction(oauth2AuthorizedClientManager);\r\n\r\n  \/\/ @formatter:off\r\n  return WebClient.builder()\r\n      .apply(oauth2Client.oauth2Configuration())\r\n      .build();\r\n  \/\/ @formatter:on\r\n}<\/pre>\n<p>As you can see, the ServletOAuth2AuthorizedClientExchangeFilterFunction class is initialized with an object parameter of the OAuth2AuthorizedClientManager class and attached to the WebClient object so that all requests using this WebClient object always have the access token.<\/p>\n<p>Now we will modify our RESTful API to use WebClient to call the resource we want:<\/p>\n<pre class=\"lang:java decode:true\">package com.huongdanjava.springsecurity;\r\n\r\nimport static org.springframework.security.oauth2.client.web.reactive.function.client.ServletOAuth2AuthorizedClientExchangeFilterFunction.clientRegistrationId;\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.web.bind.annotation.GetMapping;\r\nimport org.springframework.web.bind.annotation.RequestParam;\r\nimport org.springframework.web.bind.annotation.RestController;\r\nimport org.springframework.web.reactive.function.client.WebClient;\r\n\r\n@RestController\r\npublic class HelloController {\r\n\r\n  @Autowired\r\n  private WebClient webClient;\r\n\r\n  @GetMapping(\"\/hello\")\r\n  public String hello(@RequestParam String name) {\r\n    \/\/ @formatter:off\r\n    String responseFromResourceServer = webClient.get()\r\n        .uri(\"http:\/\/localhost:8081\/hello\")\r\n        .attributes(clientRegistrationId(\"huongdanjava1\"))\r\n        .retrieve()\r\n        .bodyToMono(String.class)\r\n        .block();\r\n    \/\/ @formatter:on\r\n\r\n    return String.format(\"%s %s\", responseFromResourceServer, name);\r\n  }\r\n}\r\n<\/pre>\n<p>The static clientRegistrationId() method of the ServletOAuth2AuthorizedClientExchangeFilterFunction class will get the client&#8217;s access token with registrationId &#8220;huongdanjava1&#8221; to pass along with the request to the Resource Server of the WebClient object.<\/p>\n<p>At this point, we have finished configuring our OAuth2 Client.<\/p>\n<p>To check the results, please start this application, Resource Server and Authorization Server in the previous article. When requesting the address <a href=\"http:\/\/localhost:8082\/hello?name=Khanh\" target=\"_blank\" rel=\"noopener\">http:\/\/localhost:8082\/hello?name=Khanh<\/a>, you will see the following results:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-21986 aligncenter\" src=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2023\/05\/working-with-authorization-server-using-spring-security-oauth2-client-4.png\" alt=\"\" width=\"700\" height=\"261\" \/><\/p>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-right kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;right&quot;,&quot;id&quot;:&quot;21981&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;0&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;0&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;4&quot;,&quot;greet&quot;:&quot;&quot;,&quot;legend&quot;:&quot;0\\\/5 - (0 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;Working with Authorization Server using Spring Security OAuth2 Client&quot;,&quot;width&quot;:&quot;0&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 0px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\">\n            <span class=\"kksr-muted\"><\/span>\n    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>In the article Implement OAuth Resource Server using Spring Security OAuth2 Resource Server, I showed you how to protect resources managed by Resource Server using an access token issued by Authorization Server. In the example of this article Implement OAuth Resource Server using Spring Security&hellip; <a href=\"https:\/\/huongdanjava.com\/working-with-authorization-server-using-spring-security-oauth2-client.html\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":14834,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1891],"tags":[],"class_list":["post-21981","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring-security","clearfix"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Working with Authorization Server using Spring Security OAuth2 Client - Huong Dan Java<\/title>\n<meta name=\"description\" content=\"In this tutorial, I guide you all on how to work with Authorization Server using Spring Security OAuth2 Client.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/huongdanjava.com\/working-with-authorization-server-using-spring-security-oauth2-client.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Working with Authorization Server using Spring Security OAuth2 Client - Huong Dan Java\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, I guide you all on how to work with Authorization Server using Spring Security OAuth2 Client.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/huongdanjava.com\/working-with-authorization-server-using-spring-security-oauth2-client.html\" \/>\n<meta property=\"og:site_name\" content=\"Huong Dan Java\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/nhkhanh2406\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/nhkhanh2406\" \/>\n<meta property=\"article:published_time\" content=\"2023-05-27T02:13:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2019\/07\/spring-security.png\" \/>\n\t<meta property=\"og:image:width\" content=\"200\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Khanh Nguyen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/KhanhNguyenJ\" \/>\n<meta name=\"twitter:site\" content=\"@KhanhNguyenJ\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Khanh Nguyen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/working-with-authorization-server-using-spring-security-oauth2-client.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/working-with-authorization-server-using-spring-security-oauth2-client.html\"},\"author\":{\"name\":\"Khanh Nguyen\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#\\\/schema\\\/person\\\/dc859d7f8cbea3b593e6738de9cbb82d\"},\"headline\":\"Working with Authorization Server using Spring Security OAuth2 Client\",\"datePublished\":\"2023-05-27T02:13:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/working-with-authorization-server-using-spring-security-oauth2-client.html\"},\"wordCount\":741,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#\\\/schema\\\/person\\\/dc859d7f8cbea3b593e6738de9cbb82d\"},\"image\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/working-with-authorization-server-using-spring-security-oauth2-client.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/spring-security.png\",\"articleSection\":[\"Spring Security\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/huongdanjava.com\\\/working-with-authorization-server-using-spring-security-oauth2-client.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/working-with-authorization-server-using-spring-security-oauth2-client.html\",\"url\":\"https:\\\/\\\/huongdanjava.com\\\/working-with-authorization-server-using-spring-security-oauth2-client.html\",\"name\":\"Working with Authorization Server using Spring Security OAuth2 Client - Huong Dan Java\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/working-with-authorization-server-using-spring-security-oauth2-client.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/working-with-authorization-server-using-spring-security-oauth2-client.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/spring-security.png\",\"datePublished\":\"2023-05-27T02:13:23+00:00\",\"description\":\"In this tutorial, I guide you all on how to work with Authorization Server using Spring Security OAuth2 Client.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/working-with-authorization-server-using-spring-security-oauth2-client.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/huongdanjava.com\\\/working-with-authorization-server-using-spring-security-oauth2-client.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/working-with-authorization-server-using-spring-security-oauth2-client.html#primaryimage\",\"url\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/spring-security.png\",\"contentUrl\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/spring-security.png\",\"width\":200,\"height\":200},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/working-with-authorization-server-using-spring-security-oauth2-client.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/huongdanjava.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Working with Authorization Server using Spring Security OAuth2 Client\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#website\",\"url\":\"https:\\\/\\\/huongdanjava.com\\\/\",\"name\":\"Huong Dan Java\",\"description\":\"Java development tutorials\",\"publisher\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#\\\/schema\\\/person\\\/dc859d7f8cbea3b593e6738de9cbb82d\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/huongdanjava.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#\\\/schema\\\/person\\\/dc859d7f8cbea3b593e6738de9cbb82d\",\"name\":\"Khanh Nguyen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg\",\"url\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg\",\"contentUrl\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg\",\"width\":1267,\"height\":1517,\"caption\":\"Khanh Nguyen\"},\"logo\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg\"},\"description\":\"I love Java and everything related to Java.\",\"sameAs\":[\"https:\\\/\\\/huongdanjava.com\",\"https:\\\/\\\/www.facebook.com\\\/nhkhanh2406\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/KhanhNguyenJ\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Working with Authorization Server using Spring Security OAuth2 Client - Huong Dan Java","description":"In this tutorial, I guide you all on how to work with Authorization Server using Spring Security OAuth2 Client.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/huongdanjava.com\/working-with-authorization-server-using-spring-security-oauth2-client.html","og_locale":"en_US","og_type":"article","og_title":"Working with Authorization Server using Spring Security OAuth2 Client - Huong Dan Java","og_description":"In this tutorial, I guide you all on how to work with Authorization Server using Spring Security OAuth2 Client.","og_url":"https:\/\/huongdanjava.com\/working-with-authorization-server-using-spring-security-oauth2-client.html","og_site_name":"Huong Dan Java","article_publisher":"https:\/\/www.facebook.com\/nhkhanh2406","article_author":"https:\/\/www.facebook.com\/nhkhanh2406","article_published_time":"2023-05-27T02:13:23+00:00","og_image":[{"width":200,"height":200,"url":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2019\/07\/spring-security.png","type":"image\/png"}],"author":"Khanh Nguyen","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/KhanhNguyenJ","twitter_site":"@KhanhNguyenJ","twitter_misc":{"Written by":"Khanh Nguyen","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/huongdanjava.com\/working-with-authorization-server-using-spring-security-oauth2-client.html#article","isPartOf":{"@id":"https:\/\/huongdanjava.com\/working-with-authorization-server-using-spring-security-oauth2-client.html"},"author":{"name":"Khanh Nguyen","@id":"https:\/\/huongdanjava.com\/#\/schema\/person\/dc859d7f8cbea3b593e6738de9cbb82d"},"headline":"Working with Authorization Server using Spring Security OAuth2 Client","datePublished":"2023-05-27T02:13:23+00:00","mainEntityOfPage":{"@id":"https:\/\/huongdanjava.com\/working-with-authorization-server-using-spring-security-oauth2-client.html"},"wordCount":741,"commentCount":0,"publisher":{"@id":"https:\/\/huongdanjava.com\/#\/schema\/person\/dc859d7f8cbea3b593e6738de9cbb82d"},"image":{"@id":"https:\/\/huongdanjava.com\/working-with-authorization-server-using-spring-security-oauth2-client.html#primaryimage"},"thumbnailUrl":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2019\/07\/spring-security.png","articleSection":["Spring Security"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/huongdanjava.com\/working-with-authorization-server-using-spring-security-oauth2-client.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/huongdanjava.com\/working-with-authorization-server-using-spring-security-oauth2-client.html","url":"https:\/\/huongdanjava.com\/working-with-authorization-server-using-spring-security-oauth2-client.html","name":"Working with Authorization Server using Spring Security OAuth2 Client - Huong Dan Java","isPartOf":{"@id":"https:\/\/huongdanjava.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/huongdanjava.com\/working-with-authorization-server-using-spring-security-oauth2-client.html#primaryimage"},"image":{"@id":"https:\/\/huongdanjava.com\/working-with-authorization-server-using-spring-security-oauth2-client.html#primaryimage"},"thumbnailUrl":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2019\/07\/spring-security.png","datePublished":"2023-05-27T02:13:23+00:00","description":"In this tutorial, I guide you all on how to work with Authorization Server using Spring Security OAuth2 Client.","breadcrumb":{"@id":"https:\/\/huongdanjava.com\/working-with-authorization-server-using-spring-security-oauth2-client.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/huongdanjava.com\/working-with-authorization-server-using-spring-security-oauth2-client.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/huongdanjava.com\/working-with-authorization-server-using-spring-security-oauth2-client.html#primaryimage","url":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2019\/07\/spring-security.png","contentUrl":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2019\/07\/spring-security.png","width":200,"height":200},{"@type":"BreadcrumbList","@id":"https:\/\/huongdanjava.com\/working-with-authorization-server-using-spring-security-oauth2-client.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/huongdanjava.com\/"},{"@type":"ListItem","position":2,"name":"Working with Authorization Server using Spring Security OAuth2 Client"}]},{"@type":"WebSite","@id":"https:\/\/huongdanjava.com\/#website","url":"https:\/\/huongdanjava.com\/","name":"Huong Dan Java","description":"Java development tutorials","publisher":{"@id":"https:\/\/huongdanjava.com\/#\/schema\/person\/dc859d7f8cbea3b593e6738de9cbb82d"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/huongdanjava.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/huongdanjava.com\/#\/schema\/person\/dc859d7f8cbea3b593e6738de9cbb82d","name":"Khanh Nguyen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2021\/07\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg","url":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2021\/07\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg","contentUrl":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2021\/07\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg","width":1267,"height":1517,"caption":"Khanh Nguyen"},"logo":{"@id":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2021\/07\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg"},"description":"I love Java and everything related to Java.","sameAs":["https:\/\/huongdanjava.com","https:\/\/www.facebook.com\/nhkhanh2406","https:\/\/x.com\/https:\/\/twitter.com\/KhanhNguyenJ"]}]}},"_links":{"self":[{"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/posts\/21981","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/comments?post=21981"}],"version-history":[{"count":3,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/posts\/21981\/revisions"}],"predecessor-version":[{"id":21988,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/posts\/21981\/revisions\/21988"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/media\/14834"}],"wp:attachment":[{"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/media?parent=21981"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/categories?post=21981"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/tags?post=21981"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}