this is a followup question to the following StackExchange question -
At the time our applications were started, Microsoft provided OAuth2, but the nodejs interface wasn't exactly complete. So we built our own to interact with their JSON API. We haven't had any issues with this. However ... there are no tests written on our end. To write tests I have to either Mock a Microsoft token or I have to figure out a way to programmatically obtain a real Microsoft OAuth token.
- OAuth begins by hitting an API endpoint, generating a callback code, and forwarding a user to Microsofts login page where the user will enter an email, password and a 2 step authentication
- On success, Microsoft will redirect the user with a valid callback "code" to the original API, where the API receives the callback code from Microsoft and under the hood reaches out to Microsoft to obtain the users details from this provided code.
- On success, a valid token is returned to the user, and under the hood the refresh details are stored for later use when the token expires.
- the user can then use the token they have been given to make all subsequent requests to API endpoints
this is my understanding of how it works, but whether or not this is correct OAuth implementation thats secondary -
How can I mock a login to Microsoft in order to fire all of my HTTP tests against my apps? Do other developers build a back door for testing endpoints when interracting with OAuth? It almost sounds like I have to write a small web-scraper to get a valid token, but that doesn't seem proper.