- Login (username, password stored in BasicNameValuePair) from your client (here Android) using the web API controller (possibly / Token if you use some samples from the Asp.Net web interface website). If successful, the access token will respond and you will save it to your client (SharedPreference or database).
- Then you just need to send the access token (no username, password anymore) to request other API controllers.
Of course, https should be used here for better security.
Examples of codes for obtaining an access token (input phase):
public static Object getAccessToken(String address, String grant_type, String username, String password) throws Exception { List<NameValuePair> params = new ArrayList<>(); params.add(new BasicNameValuePair("grant_type", grant_type)); params.add(new BasicNameValuePair("username", username)); params.add(new BasicNameValuePair("password", password));
Inside makeHTTPRequest, for an access token:
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); httpPost.setEntity(new UrlEncodedFormEntity(parameters));
source share