Note that there are some explanatory texts on larger screens.

plurals
  1. POQuestions About Consuming Your Own API with OAuth
    primarykey
    data
    text
    <p>I'm building a RESTful API for a project I'm working on and I'd like to make the main application consume the API because:</p> <ol> <li>It will result in having one set of code to maintain</li> <li>Should we decide to expose the API for 3rd party devs it will already be done</li> <li>It opens up the possibility to make mobile applications that consume it</li> <li>I really want to learn how to do it</li> </ol> <p>The API will be hosted on a subdomain <code>https://api.example.com</code> and the main web application will be hosted at the root domain <code>https://example.com</code>. </p> <p>Conceptually I understand how everything works, but my main question is how the authentication flow will change if, at all. Ordinarily 3rd party apps would: </p> <ol> <li>Obtain a request token from <code>https://api.example.com/request_token</code></li> <li>Redirect the user to authenticate on <code>https://api.authenticate.com/authorize</code></li> <li>Get redirected back to the 3rd party application</li> <li>Obtain an access token from <code>https://api.example.com/access_token</code></li> </ol> <p>Since I control both domains, can I do something similar to:</p> <ol> <li>Obtain a request token when the user lands on the login screen at <code>https://www.example.com</code></li> <li>The user authenticates using a form on <code>https://www.example.com</code> that calls the same code as <code>https://api.example.com/authorize</code></li> <li>If the credentials are valid, the request token is swapped for the access token</li> <li>Access token is saved in the session and expires when the user logs out like it normally would</li> </ol> <p>Step 3 feels like it's wrong since there will be duplicate code, but wouldn't it open me up to XSS attacks is the login form on <code>https://www.example.com</code> sent the data to <code>https://api.example.com</code> since they are <em>technically</em> different domains?</p> <p>Am I overcomplicating this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload