devise vs. devise_token_auth: How to handle authentication for both a web app and API
Asked Answered
K

1

6

I'm writing an application that will primarily be accessed via API, but will also have views for editing via web app.

I would like to create a User model with authentication and authorization across both platforms.

I'm having trouble understanding the relationship between the devise and devise_token_auth libraries, other than that the former is recommended for most rails apps and the latter is great for API-only authentication.

For my case, what is the appropriate library to use, or should I be using both? Should I be generating the User model via devise and then adding the token auth to it? Do both systems use different authentication schemes? I'm just trying to understand why devise_token_auth exists apart from devise.

I'm also just a bit confused about the added complexity of token-based authentication. What would be wrong with simply having the users be registered and managed through devise, generating an API secret key for them, and then having them sign their API requests with that. Why the need for token based auth in the API?

Knew answered 17/11, 2017 at 18:46 Comment(0)
C
2

devise_token_auth is an advanced method of API authentication which may, or may not, be overkill for your application. Essentially, a new token is generated for each API request.

Depending on what your needs are, you may be fine with token-based authentication, or perhaps even HTTP Basic auth, which devise supports out of the box.

Colorado answered 17/11, 2017 at 22:42 Comment(1)
See github.com/plataformatec/devise/wiki/… for more information on using HTTP Basic Auth with deviseWanhsien

© 2022 - 2024 — McMap. All rights reserved.