hbagdi / go-unsplash

Go Client for the Unsplash API
https://unsplash.com
MIT License
74 stars 13 forks source link

use 2-legged client auth #21

Closed klauern closed 7 years ago

klauern commented 7 years ago

As per the documentation, 2-legged OAuth2 is preferred if you're not running as a third party. As this is a provided feature, it's simpler to set up and requires one less parameter.

hbagdi commented 7 years ago

@klauern, API provides certain endpoints which have to be accessed with a authenticated user (eg- like a photo, add a photo) so it is necessary to use the staticsource method for automated testing.

I'm not sure if I'm making sense.

klauern commented 7 years ago

That's fine, but you authenticate with the clientcredentials.Config, right? At least, the way I'm testing it, I'm getting mostly working with this, and my application configuration has this set.

image

Is this not workable? I'm no OAuth expert, so you're quite possibly right. That said, I had some issues using the StaticToken.... that you had, and I found this work instead, at least from a client-testing perspective.

hbagdi commented 7 years ago

clientcredentials.Config can be used and it'll most probably work with endpoints which don't need user authentication but will fail otherwise.

Do the following-

$ cat "unsplash_usertoken=<YOUR-AUTH-TOKEN>" > auth.env

If you don't have an auth token you can generate one with some work. I can help you with that. Let me know.t

The method you propose is the way to go but here we have constraints for test automation.

klauern commented 7 years ago

Hello. I teased out the commit to another branch, and then created another pull request. Let me know if that works for you.

hbagdi commented 7 years ago

Closing this for now, reopen if we need further discussion.