title: Spring Boot2 Oauth2 Implicit Flow - http://localhost:8080/oauth/authorize getting Access Denied
body: <p>I have created a Spring Boot 2 Application, integrated SpringFox Swagger 2.8.0 with Implicit Oauth2 Grant for Authentication and Authorization.</p>
  
  <p>The Code is working fine but when I click Authorize button it redirects to the </p>
  
  <blockquote>
    <p><a href="http://localhost:8080/oauth/authorize?response_type=token&amp;client_id=test-app-client-id&amp;redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fwebjars%2Fspringfox-swagger-ui%2Foauth2-redirect.html&amp;scope=read&amp;state=U3VuIE9jdCAxNCAyMDE4IDIwOjQyOjUwIEdNVCswNTMwIChJbmRpYSBTdGFuZGFyZCBUaW1lKQ%3D%3D" rel="noreferrer">http://localhost:8080/oauth/authorize?response_type=token&amp;client_id=test-app-client-id&amp;redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fwebjars%2Fspringfox-swagger-ui%2Foauth2-redirect.html&amp;scope=read&amp;state=U3VuIE9jdCAxNCAyMDE4IDIwOjQyOjUwIEdNVCswNTMwIChJbmRpYSBTdGFuZGFyZCBUaW1lKQ%3D%3D</a></p>
  </blockquote>
  
  <p>but shows Access Denied like as shown below. </p>
  
  <p>My complete project is available in <strong><a href="https://github.com/AlexMan123/spring-boot2-oauth2-sample" rel="noreferrer">GitHub</a></strong></p>
  
  <p><strong>MainApplication.java</strong></p>
  
  <pre><code>@EnableSwagger2
  @SpringBootApplication
  @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
  @RestController
  public class MainApplication /*extends WebMvcConfigurerAdapter*/
  {
  
      public static void main(String[] args)
      {
          SpringApplication.run(MainApplication.class, args);
      }
  
      @RequestMapping("/user")
      public Principal user(Principal user) {
          return user;
      }
  
      @Bean
      SecurityConfiguration security() {
        return SecurityConfigurationBuilder.builder()//&lt;19&gt;
            .clientId("test-app-client-id")
            .build();
      }
  
      @Bean
      SecurityScheme oauth() {
            List&lt;GrantType&gt; grantTypes = new ArrayList&lt;&gt;();
            ImplicitGrant implicitGrant = new ImplicitGrant(new LoginEndpoint("http://localhost:8080/oauth/authorize"),"access_code");
            grantTypes.add(implicitGrant);
            List&lt;AuthorizationScope&gt; scopes = new ArrayList&lt;&gt;();
            scopes.add(new AuthorizationScope("read","Read access on the API"));
          return new OAuthBuilder()
                  .name("SECURITY_SCHEME_OAUTH2")
                  .grantTypes(grantTypes)
                  .scopes(scopes)
                  .build();
      }
  
      @Bean
      public Docket docket()
      {
          return new Docket(DocumentationType.SWAGGER_2)
              .select()
              .apis(RequestHandlerSelectors.basePackage(getClass().getPackage().getName()))
              .paths(PathSelectors.any())
              .build()
              .securitySchemes(Collections.singletonList(oauth()))
              .apiInfo(generateApiInfo());
      }
  
  
      private ApiInfo generateApiInfo()
      {
          return new ApiInfo("Sample Service", "This service is to check Sample Service.", "Version 1.0",
              "Sample Service", "123@test.com", "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0");
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/eO74X.png" rel="noreferrer"><img src="https://i.stack.imgur.com/eO74X.png" alt="enter image description here"></a> </p>
  
  <h2>Update 1</h2>
  
  <p>I have added the security and the passwordencoder configure suggested from <strong>@AlexanderPetrov</strong>. Things are working fine, when I add <code>@EnableResourceServer</code> my login screen is showing <strong>Full authentication is required to access this resource</strong>  like as shown below</p>
  
  <p><a href="https://i.stack.imgur.com/VIi9P.png" rel="noreferrer"><img src="https://i.stack.imgur.com/VIi9P.png" alt="enter image description here"></a></p>
  
  <p>Can anyone please help me on this</p>