title: Oauth2 and Spring-Security: Fail on authentication using Oauth2 and spring-security
body: <p>I want to use Oauth2 and Spring-security with rest web service. I am new for this, i am trying to create configuration with the help of some websites. Still, i clearly not understand how and what is the flow for oauth authenticate for rest service. i am using latest dependencies <a href="https://stackoverflow.com/questions/24926166/oauth2-and-spring-security-java-lang-illegalstateexception-no-webapplicationco">Click on the link for see my configurations</a>. I am using database for store clients information and tokens. when i trying to access the token, using follwoing url with post request and post body: </p>
  
  <pre><code>http://localhost:8080/empirecl-api/oauth/token
  grant_type=password&amp;username=a@a.com&amp;password=password&amp;client_id=my-client-with-secret&amp;client_secret=ak_secret
  </code></pre>
  
  <p>The basic authentication pop-up box will appear. I am using chrome rest postman client. I have user table in my database where i store, username and password, when i enter those <code>username</code> and <code>password</code>, the authentication fail, If i use i my <code>client_id</code> and <code>client_secret</code> as a <code>username</code> and <code>password</code>, the authentication is fail. When i cancel the pop of basic authentication following <code>json</code> is return: </p>
  
  <pre><code>{
  "error": "unauthorized",
  "error_description": "No client with requested id: a@a.com"
  }
  </code></pre>
  
  <p>I am unable to figure out what will happen.</p>
  
  <p>When i trying to access following url with get reqquest: </p>
  
  <pre><code>http://localhost:8080/empirecl-api/oauth/authorize?grant_type=password&amp;username=a@a.com&amp;password=password
  </code></pre>
  
  <p>The following <code>error</code> will return: </p>
  
  <pre><code>{
  "error": {
      "error": "invalid_client",
      "error_description": "Bad client credentials"
  }
  }
  </code></pre>
  
  <p>When i check the error in console, of eclipse, the follwoing error is display: </p>
  
  <pre><code>AuthorizationEndpoint:436 - Handling ClientRegistrationException error: No client with requested id: null
  </code></pre>
  
  <p>How i resolve this problem and how to use Oauth with my rest api. I also want to secure my all rest url with Oauth. </p>