RESTful, user authentication, and Django-tastypie
Asked Answered
C

2

8

Apologies for the beginner question.

I'm a little bit confused about the general approach to using RESTful services in conjunction with distinct users. In particular, I'm primarily concerned with developing an API that only I will use through the various applications that I write, namely, a web application, and potentially some mobile apps that will all access the same data.

(1) Is a rest API produced by something like django-tastypie appropriate (or even best practice) for non-public use -- i.e., when I only want to grant access to this data through my applications?

(2) In creating login-access to the Restful API, am I creating a login for all of the users of my web-app -- or am I creating a login for myself and my web application? Should user accounts to my webapp be considered distinct from accounts for accessing the Restful API?

Basically, I'm wanting to create an application using Django and django-tastypie that will allow users to login, create & view objects, subscribe to users and view their objects. I want to use the Tastypie API for my own javascript purposes, to ease with the creation of serializing and updating the relevant data in my views. Where do these user accounts fit within this picture? Thanks!

Caphaitien answered 18/5, 2012 at 3:43 Comment(1)
Your point number 2 is not very clear to me. Can't you have your applications as your users of the api(which again is a django project in itself, i am guessing)?Woodwind
O
4

If I understand correctly, you are dealing with two separate auth concerns here: (A) Access to the API - Your web/mobile app only (B) Access to user data via the API - For users via your web/mobile app

For (A), you could just authenticate on a secret key. So your web or mobile front end would send that key with every API request, which would guarantee that you are receiving requests only from clients that you authorize.

If you want to use different keys for different apps, you can create a simple django model to keep track of them, and add new keys or revoke them as necessary.

If you use SSL for everything, you should be safe from sniffing attacks to discover your key. I think the weakest point here would be that someone could possible reverse engineer your mobile app to find the key, since you would have to store the key in the app.

For (B), use the django auth system. The tastypie Basic or ApiKey Authenticators should allow you to log users in and via the API, and based on their permissions, access or create data. I think that's what you were asking in the second question?

I don't think you can use the same auth models for both (A) and (B) if you are using sessions, because you can't have two active sessions at the same time.

Overskirt answered 9/7, 2012 at 5:40 Comment(2)
Thanks for the answer. I've since moved on a bit, but was still confused by the basic principles.Caphaitien
@Overskirt what's the difference here between ApiKey Authentication and the secret key authentication you described in (A)?Mizzle
U
0

I am new with Django and DRF and i could use some help.I just created a Note app and i am considering if i am gonna need a user/authors/clients second app in my project. I just want the user to be able to login , create their own notes , and the notes should have one (or more) authors so that i can filter the userdata.Any help ?

PS: I am a beginner too so we can keep in touch if you want.

Unrefined answered 13/3, 2014 at 15:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.