lundi 30 octobre 2017

Testing OAuth in controllers

I'm using the Google calendar API. This particular way I'm using requires OAuth, and to be honest I'm not that familiar with it. But I am trying work on my TDD. What are the best ways to test OAuth interactions?

If I simply make an http request: http://ift.tt/1995sls?

I get this JSON back form Google's api:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}

This totally makes sense because I have authorized who's calendars I'm getting back. I can handle this in code just fine. But mocking it out in a controller test I can't seem to figure out how to do that.

All this being said. I'm not looking for an answer because I understand that this question is a bit vague. I'm simply looking to be pointed towards some good blog posts or best practices when it comes to mocking OAuth. Thanks for your help!

Aucun commentaire:

Enregistrer un commentaire