stormpath / Turnstile

An authentication framework for Swift.
Apache License 2.0
165 stars 29 forks source link

Feature/add support for digits #19

Closed kdawgwilk closed 7 years ago

kdawgwilk commented 7 years ago

Finally got some time to add support for Digits. I still don't understand completely how Turnstile works so I am sure there are things I could fix in here and I would happily do so. Everything seemed to be working pretty well on my end except for AccessTokens but I think that has something to do with the way I set things up in my Vapor app. The API I am building using Turnstile for Authentication is an open source project I worked on for school and a hackathon posted here

kdawgwilk commented 7 years ago

Looks like a test related to Facebook access token is failing but I didn't touch anything related to Facebook so not sure what it needs

edjiang commented 7 years ago

Yep! The FB test will fail since Travis won't use encrypted data (the facebook api keys) for tests for PRs, since it's an attack vector to get the encrypted data.

Thanks for submitting this! I'll look into it and get it merged =]

kdawgwilk commented 7 years ago

I will try to get around to writing some tests but I am slammed right now so it might be a week or so

edjiang commented 7 years ago

No worries! I've been moving to a new place this week so pretty busy as well. We'll get this merged, don't worry!

edjiang commented 7 years ago

Hey @kdawgwilk, I made some modifications to your PR to clean up a few things -- you can see the comments along each commit. I haven't personally tested this with Digits yet, so need to do that -- but what do you think of the general direction?

kdawgwilk commented 7 years ago

All the changes look good to me but I still don't understand how I can authenticate a Digits account with an access token or API keys? I guess that comes down to how the session works. I can login with digits perfectly but I can't get auth to work on subsequent calls using either an AccessToken or APIKey. What format do those need to be sent in the request so that Turnstile picks them up and calls the right authenticate(credentials: Credentials) in my User model?

edjiang commented 7 years ago

Gotcha. If you're using Vapor, it should automatically persist your session into a session cookie.

The vapor session manager resolves your session into a user ID, which it passes back to Turnstile as an Identifier.

See https://github.com/stormpath/Turnstile-Vapor-Example/blob/master/Sources/App/Models/DemoUser.swift#L52

If you were to do an API Key or AccessToken, you'd basically do the same thing but handle the "exchange" of the Digits authentication data to your own API Key / access token yourself.

kdawgwilk commented 7 years ago

Alright this is ready to get merged if you are okay with it 👍

edjiang commented 7 years ago

Awesome! I know I made some good sized changes to your code, so glad everything is working!

edjiang commented 7 years ago

Would like to get some documentation written before tagging a release. @kdawgwilk would you like to modify the README to accommodate?

kdawgwilk commented 7 years ago

Yeah will do! I will try and get that done tonight

edjiang commented 7 years ago

Awesome, thanks! I'll put you as a contributor so you can make a branch directly on here.