javascript - SPA's w/ Angular and cookie based authentication -
I use the Web Framework Cookie (or token) based authentication when a user registers a postback and the server cookie Inserts an authentication token that adds users to the browser. All subsequent requests include this token and therefore are safe in that sense.
My question : I have to refresh a full page postback, does a user register for keeping the token on the user's browser? Or can I just return a successful token (by AJAX) on the server to successful user registration (also done through AJAX)? If possible, I like it. Thank you. If your infrastructure returns token back, you must add it to the header for all subsequent requests. Additional code is required to make this permanent (example: writing it in local storage) Headers know that your framework is wanted :) But I can assume That your login administrator might look like this: The subsequent requests will have a edited Do: Yes, set up a cookie (in javascript or from server And it is sent on every request (like all cookies in the internet world) - If you are also developing then the backend will become very elegant, send a cookie to the backend customer, and not be written manually As you have commented in ^ _ ^ A cookie is something professional : an expiration date and something bad: reading it from javascript Not really elegant (Usually a cover Lib, corner-cookie browser compatibility). When both cookies expire or the token is invalid (you will get a 40x response) You Failure use some angular.js code < / Div>
Angular Module ('cool module', []). Controller ('CoolController' function ($ range, $ http) {$ scope.loginButton = function () {// Username and password $ http.post ('/ api / login', {$ scope.username, $ Scope.password)}} .success (function (data, position, header, config) {$ http.defaults.headers.common ['x -may-token'] = data.token;})}}} )
x-me-token header, which usually works for identity
Comments
Post a Comment