title: OAuth2 from Android to my Django API requires to go to /accounts/login
body: <p>So I was trying to implement a feature on my android app where users can register and login to the app. I made it where the user credentials are stored to an external and can be validated with the Django REST API I made. </p>
  
  <p>So before I can let my app access that API page, I have to make sure it goes with OAuth2 rules. However, it requires me to login to an <code>/accounts/login</code> page. Do I need to make that page or can I change the url if don't want that path or maybe not login as admin at all? </p>
  
  <p>It keeps me wanting to login before I can authorize my app.</p>
  
  <p>login.java</p>
  
  <pre><code>public class Login extends AppCompatActivity {
  
      Button LoginButton, RegButton;
      EditText uUserName, uPassWord;
      WSAdapter.SendAPIRequests AuthHelper;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_login);
  
          //SetupHomeBtn = (ImageButton) findViewById(R.id.SetupHomeBtn);
  
          LoginButton = (Button) findViewById(R.id.LoginButton);
          RegButton = (Button) findViewById(R.id.LoginRegister);
  
          uUserName = (EditText) findViewById(R.id.LoginUserBox);
          uPassWord = (EditText) findViewById(R.id.LoginPassBox);
  
          //AuthHelper = new WSAdapter().new SendDeviceDetails();
  
          // Moves user to the main page after validation
          LoginButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  // gets the username and password from the EditText
                  String strUserName = uUserName.getText().toString();
                  String strPassWord = uPassWord.getText().toString();
  
                  //startActivity(new Intent(Login.this, Posts.class));
  
                  // To authorize oauth for requesting access token
                  OAuthClientRequest request = null;
  
                  try {
                      // sends authorization request with credentials to the server
                      request = OAuthClientRequest
                              .authorizationLocation("http://192.168.0.18:8000/auth/authorize")
                              .setClientId("mNUNXI4MinYyVvsRi1VPiv7ltrZWBOzr3OfnHJa1").setRedirectURI("http://oauthresponse")
                              .buildQueryMessage();
                  } catch (OAuthSystemException e) {
                      Log.d("TAG", "OAuth request failed", e);
                  }
  
                  // authentication service requires &amp;reponse_type=code
                  Intent intent = new Intent(Intent.ACTION_VIEW,
                          Uri.parse(request.getLocationUri() + "&amp;response_type=code"));
                  startActivity(intent);
  
                  // API url duh
                  String APIUrl = "http://192.168.0.18:8000/token-auth/";
  
                  // If the user is authenticated, then transfer to the MainActivity page
                  if (APIAuthentication(strUserName, strPassWord, APIUrl)){
                      startActivity(new Intent(Login.this, Posts.class));
                  }
              }
          });
  
  
          RegButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  // gets the username and password from the EditText
                  startActivity(new Intent(Login.this, Register.class));
              }
          });
  
      }
  
      // to handle authorization for the redirect_url
      @Override
      protected void onNewIntent(Intent intent)
      {
          super.onNewIntent(intent);
          Uri uri = intent.getData();
  
          if (uri != null &amp;&amp; uri.toString()
                  .startsWith("http://oauthresponse"))
          {
              String code = uri.getQueryParameter("code");
          }
      }
  
      private boolean APIAuthentication(String un, String pw, String url){
          // when it wasn't static -&gt; AuthHelper = new WSAdapter().new SendAPIRequests();
          AuthHelper = new WSAdapter.SendAPIRequests();
  
          JSONObject postData = new JSONObject();
          try {
              // Attempt to input info to the Django API
              postData.put("username", un);
              postData.put("password", pw);
  
              // Putting the data to be posted in the Django API
              //AuthHelper.execute(url, postData.toString());
  
              return true;
          } catch (JSONException e) {
              e.printStackTrace();
          }
  
          return false;
      }
  }
  </code></pre>