python - Authenticating Developers with APIKey and Users with BasicAuth/OAuth -


i've looked around can't seem find canonical answer. i'm trying follow best practices. maybe i'm thinking of wrong way.

i'm thinking of api users 2 different types: developers , end users, separate django models in separate applications.

developers build clients api, , have access resources of api without need of users login in. limit access, require them register , in exchange give them api key. dogfood say, build site frontend using angular , ios app. once developers build api clients, users of site, have created user account, use api clients created developers. in request clients expect developer name, api_key username/password (digest, if our own trusted client , oauth token thid party developers). require check 1) developers allowed use api checking apikey, , 2) authenticate end user. possible in tastypie?

am going wrong way? how double authentication?

we run production site exact scheme. of course you'll have own tunning. general idea good. have oauth inplace too, we've found it's not worth it. oauth complicated cases.

i'll explain do.

this app/developers part:

  1. we identify "apps" (ios, android, bb, site). each app has apiclient instance model. apiclient has 3 attrs: name, public key, , private key.

  2. we exchange public , private keys through safe channel apiclient owner (the app).

  3. the app must send every request indicating public key , signature generated private key (using hmac).

  4. everytime request, public key request, in db, see app belongs (the name) , check signature. if ok, request fulfilled.

for user authentication part:

  1. to authenticate user use other model apikey (provided tastypie). each user has apikey. model stores unique (we random) string. when user gets app he/she logs in api. app should issue request similar one:

    post /api/v1/login/ { 'username': 'xxx', 'password': 'xxx' }

    (please note need pass previous public/private key auth)

  2. if user provided right credentials return apikey unique key.

  3. every following request made app in behave of user must include key. that's way identify user trying each action.

an example of last part:

  1. user jon logs in in ios app. (using regular username , password)
  2. the app sends request:

    post /api/v1/login/ { 'username': 'jon', 'password': 'snow' }

  3. we have login api method. check if user exists , if pass ok. suppose it's ok.

  4. we sent apikey info:

    200 ok { 'username': 'jon', 'key': '$123$' }

  5. the app has authenticated user. needs use credentials.

  6. the user tries in app. suppose tries datetime app. app issue request:

    get /api/v1/date/

    authorization: apikey jon:$123$

that's it. it's not super safe. apikeys not invalidated. that's because create our own internal apps. it's worth note borrow stuff tastypie this. check out: http://django-tastypie.readthedocs.org/en/latest/authentication.html#apikeyauthentication


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -