title: Spring oauth security wrong username or password 401 Unauthorized
body: <pre><code>@Configuration
  public class SecurityConfiguration extends WebSecurityConfigurerAdapter
  {
  
     @Override protected void configure(HttpSecurity http) throws Exception
     {
        http.formLogin();
        http.authorizeRequests().anyRequest().authenticated();
     }
  
     @Bean
     public UserDetailsService userDetailsService()
     {
        UserDetailsManager userDetailsManager = new InMemoryUserDetailsManager();
        UserDetails user = User.withUsername(&quot;emoleumassi&quot;)
                               .password(&quot;today&quot;).authorities(&quot;write&quot;)
                               .build();
        userDetailsManager.createUser(user);
        return userDetailsManager;
     }
  
     @Bean
     public PasswordEncoder passwordEncoder()
     {
        return NoOpPasswordEncoder.getInstance();
     }
  
     @Bean
     @Override
     public AuthenticationManager authenticationManagerBean() throws Exception
     {
        return super.authenticationManagerBean();
     }
  }
  
  </code></pre>
  <p>AuthorizationServer</p>
  <pre><code>@Configuration
  @EnableAuthorizationServer
  public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter
  {
     @Autowired private AuthenticationManager authenticationManager;
  
     @Override
     public void configure(ClientDetailsServiceConfigurer clients) throws Exception
     {
        clients.inMemory().withClient(&quot;client&quot;).secret(&quot;secret&quot;).scopes(&quot;write&quot;).authorizedGrantTypes(&quot;password&quot;);
     }
  
     @Override
     public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception
     {
        endpoints.authenticationManager(authenticationManager);
     }
  }
  </code></pre>
  <p>my dependencies:</p>
  <pre><code> SPRING_BOOT_VERSION = &quot;2.6.6&quot;
   implementation &quot;org.springframework.boot:spring-boot-starter-web:${SPRING_BOOT_VERSION}&quot;
   implementation 'org.springframework.boot:spring-boot-starter-security:2.6.6'
   implementation 'org.springframework.security.oauth:spring-security-oauth2:2.5.1.RELEASE'
  </code></pre>
  <p>i received <code>401 Unauthorized</code></p>
  <p><a href="https://i.stack.imgur.com/G0uPl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/G0uPl.png" alt="enter image description here" /></a></p>