passport.js passport.initialize() middleware not in use

Follow the example to avoid the out-of-order middleware hell that express makes it so easy to enter. Straight from the docs. Note how yours does not match this exactly. var app = express(); app.use(require(‘serve-static’)(__dirname + ‘/../../public’)); app.use(require(‘cookie-parser’)()); app.use(require(‘body-parser’).urlencoded({ extended: true })); app.use(require(‘express-session’)({ secret: ‘keyboard cat’, resave: true, saveUninitialized: true })); app.use(passport.initialize()); app.use(passport.session()); Docs cookieParser session … Read more

RESTful web service – how to authenticate requests from other services?

After reading your question, I would say, generate special token to do request required. This token will live in specific time (lets say in one day). Here is an example from to generate authentication token: (day * 10) + (month * 100) + (year (last 2 digits) * 1000) for example: 3 June 2011 (3 … Read more

Token Authentication for RESTful API: should the token be periodically changed?

It is good practice to have mobile clients periodically renew their authentication token. This of course is up to the server to enforce. The default TokenAuthentication class does not support this, however you can extend it to achieve this functionality. For example: from rest_framework.authentication import TokenAuthentication, get_authorization_header from rest_framework.exceptions import AuthenticationFailed class ExpiringTokenAuthentication(TokenAuthentication): def authenticate_credentials(self, … Read more

Should JWT be stored in localStorage or cookie? [duplicate]

I like the XSRF Double Submit Cookies method which mentioned in the article that @pkid169 said, but there is one thing that article doesn’t tell you. You are still not protected against XSS because what the attacker can do is inject script that reads your CSRF cookie (which is not HttpOnly) and then make a … Read more

What’s the appropriate HTTP status code to return if a user tries logging in with an incorrect username / password, but correct format?

If you are strictly using the HTTP authentication framework provided by RFC 7235 for your REST API, the correct HTTP code would actually be 401. From the RFC: The 401 (Unauthorized) status code indicates that the request has not been applied because it lacks valid authentication credentials for the target resource. The server generating a … Read more

Basic HTTP and Bearer Token Authentication

Try this one to push basic authentication at url: curl -i http://username:password@dev.myapp.com/api/users -H “Authorization: Bearer mytoken123” ^^^^^^^^^^^^^^^^^^ If above one doesn’t work, then you have nothing to do with it. So try the following alternates. You can pass the token under another name. Because you are handling the authorization from your Application. So you can … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)