title: Android Login Authentication with Retrofit
body: <p>I have a LoginActivity, which gets a username and password.  I'm trying to receive an authentication token using a POST Retrofit 2 and OkHTTP.  I've created the service, which builds the retrofit adapter, as well as the OkHttp client.  I have an interface, but this is where my problems start.</p>
  
  <p>I have to post my credentials(username and password from the login) in a FormEncodedURL to the backend to receive the token, which I have a POJO for called AccessToken.  I'm really not sure I'm doing this correctly with the callback method, etc.</p>
  
  <p>The URL needs to look like 
  <a href="http://xxxxxxxxxxxxxxxx/token/username=smcnary%40metrostudy.com&amp;password=xxxxxx&amp;grant_type=password" rel="nofollow">http://xxxxxxxxxxxxxxxx/token/username=smcnary%40metrostudy.com&amp;password=xxxxxx&amp;grant_type=password</a></p>
  
  <p>Please let me know if there's anything else needed regarding helping me with this post as I'm rather new to android development and stacked. </p>
  
  <p>My POST call looks like this : </p>
  
  <pre><code> @POST("token")
  Call&lt;AccessToken&gt; getAuthToken(@Body User user);
  </code></pre>
  
  <p>Where the User model is : </p>
  
  <pre><code>public class User {
  @SerializedName("password")
  String password;
  @SerializedName("username")
  String email;
  String grantType;
  public User(String email, String password, String grantType ) {
      this.email = email;
      this.password = password;
      this.grantType = grantType;
  }}
  </code></pre>
  
  <p>And the AccessToken Model is: </p>
  
  <pre><code>public class AccessToken {
  
  private String accessToken;
  private String tokenType;
  private Integer expiresIn;
  private String name;
  private String title;
  private String picImageBase64String;
  private String Issued;
  private String Expires;
  private Map&lt;String, Object&gt; additionalProperties = new HashMap&lt;String, Object&gt;();
  
  public String getAccessToken() {
      return accessToken;
  }
  
  public void setAccessToken(String accessToken) {
      this.accessToken = accessToken;
  }
  
  public String getTokenType() {
      return tokenType;
  }
  
  public void setTokenType(String tokenType) {
      this.tokenType = tokenType;
  }
  
  public Integer getExpiresIn() {
      return expiresIn;
  }
  
  public void setExpiresIn(Integer expiresIn) {
      this.expiresIn = expiresIn;
  }
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
  public String getTitle() {
      return title;
  }
  
  public void setTitle(String title) {
      this.title = title;
  }
  
  public String getPicImageBase64String() {
      return picImageBase64String;
  }
  
  public void setPicImageBase64String(String picImageBase64String) {
      this.picImageBase64String = picImageBase64String;
  }
  
  public String getIssued() {
      return Issued;
  }
  
  public void setIssued(String Issued) {
      this.Issued = Issued;
  }
  
  public String getExpires() {
      return Expires;
  }
  
  public void setExpires(String Expires) {
      this.Expires = Expires;
  }
  
  public Map&lt;String, Object&gt; getAdditionalProperties() {
      return this.additionalProperties;
  }
  
  public void setAdditionalProperty(String name, Object value) {
      this.additionalProperties.put(name, value);
  }
  </code></pre>
  
  <p>Here is the logic in the LoginActivity</p>
  
  <pre><code>public void login() {
      Log.d(TAG, "Login");
  
      if (!validate()) {
          onLoginFailed();
          return;
      }
  
      _loginButton.setEnabled(false);
  
      final ProgressDialog progressDialog = new ProgressDialog(LoginActivity.this,
              R.style.AppTheme);
      progressDialog.setIndeterminate(true);
      progressDialog.setMessage("Authenticating...");
      progressDialog.show();
  
      String email = _emailText.getText().toString();
      String password = _passwordText.getText().toString();
      String grantType = "grant_type=password";
      User user = new User(email, password, grantType);
      Call&lt;AccessToken&gt; call = figgApiService.getAuthToken(user);
      call.enqueue(new Callback&lt;AccessToken&gt;() {
          @Override
          public void onResponse(Call&lt;AccessToken&gt; call, Response&lt;AccessToken&gt; response) {
              int statusCode = response.code();
              AccessToken accesstoken = response.body();
          }
  
          @Override
          public void onFailure(Call&lt;AccessToken&gt; call, Throwable t) {
  
          }
      });
  </code></pre>