title: Android : how to access the access token from spring secuity Oauth server using post request
body: <p>I have developed a oauth spring security project in myserver.When a client request for authentication the server check the client credentials and user credentials and issue a access token if the request is valid.The request should contain client credentials (that is, client_id &amp; client_secret),user credentials (that is, username and password) and the grant type as password.Now i want to setup an oauth consumer in my android application which request to this oauth server with the specified data for access token.How can i do that in android? If anyone knows that please help me to do that.Below is my spring security oauth configuration.</p>
  
  <p>spring-security.xml :</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:oauth="http://www.springframework.org/schema/security/oauth2"
  xmlns:sec="http://www.springframework.org/schema/security"
  xmlns:mvc="http://www.springframework.org/schema/mvc"
  xsi:schemaLocation="http://www.springframework.org/schema/security/oauth2
  http://www.springframework.org/schema/security/spring-security-oauth2-2.0.xsd
  http://www.springframework.org/schema/mvc
  http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
  http://www.springframework.org/schema/security
  http://www.springframework.org/schema/security/spring-security-3.2.xsd
  http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-4.1.xsd "&gt;
  &lt;http pattern="/oauth/token" create-session="stateless"  authentication-manager-ref="authenticationManager"
      xmlns="http://www.springframework.org/schema/security" &gt; 
  
      &lt;intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_FULLY" method="GET" /&gt;
      &lt;anonymous enabled="false" /&gt;
      &lt;http-basic entry-point-ref="clientAuthenticationEntryPoint" /&gt;
      &lt;custom-filter ref="clientCredentialsTokenEndpointFilter" before="BASIC_AUTH_FILTER" /&gt; 
      &lt;access-denied-handler ref="oauthAccessDeniedHandler" /&gt;
  &lt;/http&gt;
  
  &lt;http pattern="/resources/**" create-session="never" entry-point-ref="oauthAuthenticationEntryPoint"
      xmlns="http://www.springframework.org/schema/security"&gt;
      &lt;anonymous enabled="false" /&gt;
      &lt;intercept-url pattern="/resources/**" method="GET" /&gt;
      &lt;!-- &lt;intercept-url pattern="/resources/**" access="IS_AUTHENTICATED_FULLY" /&gt; --&gt;
      &lt;custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" /&gt;
      &lt;access-denied-handler ref="oauthAccessDeniedHandler" /&gt;
  &lt;/http&gt;
  
  &lt;http pattern="/logout" create-session="never" 
      entry-point-ref="oauthAuthenticationEntryPoint"
      xmlns="http://www.springframework.org/schema/security"&gt;
      &lt;anonymous enabled="false" /&gt;
      &lt;intercept-url pattern="/logout" method="GET" /&gt;
      &lt;sec:logout invalidate-session="true" logout-url="/logout" success-handler-ref="logoutSuccessHandler"   /&gt;
      &lt;custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" /&gt;
      &lt;access-denied-handler ref="oauthAccessDeniedHandler" /&gt;
  &lt;/http&gt;
  
  &lt;bean id="logoutSuccessHandler" class="com.example.myproject.oauth.LogoutImpl" &gt;
      &lt;property name="tokenstore" ref="tokenStore"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="oauthAuthenticationEntryPoint"
      class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint"&gt;
  &lt;/bean&gt;
  
  &lt;bean id="clientAuthenticationEntryPoint"
      class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint"&gt;
      &lt;property name="realmName" value="springsec/client" /&gt;
      &lt;property name="typeName" value="Basic" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="oauthAccessDeniedHandler"
      class="org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler"&gt;
  &lt;/bean&gt;
  
  &lt;bean id="clientCredentialsTokenEndpointFilter"
      class="org.springframework.security.oauth2.provider.client.ClientCredentialsTokenEndpointFilter"&gt;
      &lt;property name="authenticationManager" ref="authenticationManager" /&gt;
  &lt;/bean&gt;
  
  &lt;authentication-manager alias="authenticationManager"
      xmlns="http://www.springframework.org/schema/security"&gt;
      &lt;authentication-provider user-service-ref="clientDetailsUserService" /&gt;
  &lt;/authentication-manager&gt;
  
  &lt;bean id="clientDetailsUserService"
      class="org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService"&gt;
      &lt;constructor-arg ref="clientDetails" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="clientDetails" class="com.example.myproject.oauth.ClientDetailsServiceImpl"/&gt;
  
  &lt;authentication-manager id="userAuthenticationManager" 
      xmlns="http://www.springframework.org/schema/security"&gt;
      &lt;authentication-provider  ref="customUserAuthenticationProvider"&gt;
      &lt;/authentication-provider&gt;
  &lt;/authentication-manager&gt;
  
  &lt;bean id="customUserAuthenticationProvider"
      class="com.example.myproject.oauth.CustomUserAuthenticationProvider"&gt;
  &lt;/bean&gt;
  
  &lt;oauth:authorization-server
      client-details-service-ref="clientDetails" token-services-ref="tokenServices"&gt;
      &lt;oauth:authorization-code /&gt;
      &lt;oauth:implicit/&gt;
      &lt;oauth:refresh-token/&gt;
      &lt;oauth:client-credentials /&gt;
      &lt;oauth:password authentication-manager-ref="userAuthenticationManager"/&gt;
  &lt;/oauth:authorization-server&gt;
  
  &lt;oauth:resource-server id="resourceServerFilter"
      resource-id="springsec" token-services-ref="tokenServices" /&gt;
  
  &lt;bean id="tokenStore"
      class="org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore" /&gt;
  
  &lt;bean id="tokenServices" 
      class="org.springframework.security.oauth2.provider.token.DefaultTokenServices"&gt;
      &lt;property name="tokenStore" ref="tokenStore" /&gt;
      &lt;property name="supportRefreshToken" value="true" /&gt;
      &lt;property name="accessTokenValiditySeconds" value="300000"&gt;&lt;/property&gt;
      &lt;property name="clientDetailsService" ref="clientDetails" /&gt;
  &lt;/bean&gt;
  
  
  &lt;mvc:annotation-driven /&gt;   &lt;!-- Declares explicit support for annotation-driven MVC controllers  @RequestMapping, @Controller --&gt;
  
  &lt;mvc:default-servlet-handler /&gt;
  
  &lt;bean id="MyResource" class="com.example.myproject.oauth.MyResource"&gt;&lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>