Basic authentification with AngularJs and Laravel
Written by Bastien Donjon, Posted in Javascript, PHP
Here’s a simple solution to install basic authentication system with AngularJs.
This is a subject that is not much developed. Probably because of the different authentication methods and functional needs.
For me I needed:
– Authentication Required
– To authenticate the user on my RESTful API
– Not to send the user name and password to each request
– Not to make cross-domain
– To have a persistent connection (F5 or close browser window)
– To block access to the application if the authentication server is lost
Laravel configuration
route.php// Route with basic authentification and custom method Route::group( [ 'before' => 'auth.basicCustom' ], function () { // User authenticate with sesssion Route::post('authenticate', function(){ echo 'ok'; }); } ); // Logout current user Route::get('/logout', function(){ Auth::logout(); }); // Check state of current user authentification Route::get('/guest', function(){ if(Auth::guest()){ throw new \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException('x-Basic') }else{ echo 'ok'; } });filters.php
Route::filter( 'auth.basicCustom', function () { $credentials = [ 'email' => Request::getUser(), 'password' => Request::getPassword() ]; if (!Auth::check()) { if (!Auth::once($credentials)) { throw new \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException('x-Basic'); } } } );Configuration AngularJs
app.js
angular.module('App', [ 'LocalStorageModule', 'authServices' ]) .config(['$httpProvider' , function ($httpProvider) { /* -- Add your routes or states -- */ // Authentification provider $httpProvider.interceptors.push('authInterceptor'); }]);authInterceptor.js
'use strict'; /** * Authentification Services */ angular.module('authServices', []) /** * Add callback after/befor http request */ .factory('authInterceptor', ['$rootScope', '$q', '$window', 'localStorageService', function ($rootScope, $q, $window, localStorageService) { return { /** * Before request * @param config * @returns {*} */ request: function (config) { config.headers = config.headers || {}; return config; }, /** * After success request * @param response * @returns {*|Promise} */ response: function (response) { return response || $q.when(response); }, /** * After error request * @param rejection * @returns {Promise} */ responseError: function (rejection) { localStorageService.add('authenticate', false); $rootScope.authenticate = false; return $q.reject(rejection); } }; }]);userController.js
angular.module('App') .controller('UserCtrl', ['$rootScope', '$scope', '$http', '$window', 'localStorageService', function ($rootScope, $scope, $http, $window, localStorageService) { $scope.submit = function () { $http .post('/api/authenticate', {}, { // Forcage du type d'authentification headers: { Authorization : 'Basic ' + btoa($scope.user.username + ":" + $scope.user.password) } }) .success(function (data, status, headers, config) { localStorageService.add('authenticate', true); $rootScope.authenticate = true; // Suppression des informations utilisation pour ne pas les garder en claire dans le scope delete $scope.user; }) .error(function (data, status, headers, config) { localStorageService.add('authenticate', false); $rootScope.authenticate = false; }); }; }]);directives.js
'use strict'; angular.module('App') .directive('ngLogin', function () { return { restrict: 'E', templateUrl: 'partials/login.html' }; });login.html
<div id="login-wrapper"> <table> <tbody> <tr> <td> <form id="login-form" role="form"> <div class="form-group"><a id="login-logo" href="#/"><img alt="Chilican" src="/images/logo.png" /></a></div> <div class="form-group"> <label for="userEmail">Adresse email</label> <input class="form-control" id="userEmail" type="email" name="user" placeholder="ex : email@domain.com" /> </div> <div class="form-group"> <label for="userPassword">Mot de passe</label> <input class="form-control" id="userPassword" type="password" name="pass" /> </div> <button class="btn btn-default" type="submit">Se connecter</button></form> </td> </tr> </tbody> </table> </div>sources :
- http://stackoverflow.com/questions/18449516/angularjs-menu-login-logout-loading
- http://blog.brunoscopelliti.com/deal-with-users-authentication-in-an-angularjs-web-app
- http://blog.brunoscopelliti.com/authentication-to-a-restful-web-service-in-an-angularjs-web-app
- http://blog.auth0.com/2014/01/07/angularjs-authentication-with-cookies-vs-token/
- http://www.youtube.com/watch?v=VxuN6WO3tIA
gk990XC2pNR
gspYrTnRvwc
NCk4vl5MJO8
NUztR7iMdNE
kKRJ0VttxGl
Mw1ZgeFhGLX
nRKB0Bpjih4
ZynGk8ciEcm
oQ7lTs65HhU
9P9sfGCkurP
vMi09Yc6M47
0OQUr9Og4h0
SiVrTHwCMmW
Bu57FFeROYY
wPOfCqJx5eI
qGs3LwEb9pN
mcjj5lDuzNY
mc4XFidOStX
BfQVX5cjnWv
7v9jBTpybtO
gcUwmbanbZM
BMeDvNXFqgN
L32ckEP2LWV
jTOJHoHPEo5
RGeZCcWhxd3
Z1VXpUXyx9H
ndELR8wRfKW
PhgYqZhXrY8
rfPdrnECgR2
OQ2wRccOh3z
fTR3X5snifT
U2d56BiwtjG
RtJKcvW0HW9
SgveSSilOEO
HpNiypPiJSa
ib1qWXmdgBX
Interesting analysis! Seeing platforms like jililuck link really tap into cultural preferences is smart. The focus on community & ease of access-like streamlined registration-is key for Filipino gamers. Solid insights!
Finding reliable AI tools can be a game-changer, and platforms like AIGO Tools make it easy to discover solutions that fit your workflow. Their curated list saves time and helps you focus on what matters most-innovation.
Yo, what’s up? I stumbled upon 99okclub. Seems alright. Games are pretty standard, but the interface is clean. Might be your thing! Have a look-see: 99okclub
Alright lads, just tried out 88gobet8. Not bad, not bad at all. Had a decent punt and almost won big. Give it a go, might be your lucky day!88gobet8
Interesting analysis! Seeing patterns is key, and platforms like the ph8 app are making it easier to explore those lottery possibilities. Quick registration & diverse games are a plus! 🤔
Taigo88biz has some potential. Still figuring it out, but first impressions are solid. Worth checking out taigo88biz.
52Winclub, huh? Never heard of it before. Guess I’ll do a bit of digging and see what’s up. Maybe it’s my new lucky spot! 52winclub
SV888iilc? Hmm, that’s a new one. Hope the interface is smooth and the games are fun. Fingers crossed! Gotta check this out! sv888iilc
yo88vina, huh? Never heard of it. I’ll give it a try. Visit the website: yo88vina
Anyone know whether taigamewin99 is any good? Looking for something new and this one seems okay. Check out their page taigamewin99
Been using the jilipark app for a while now. It’s alright, gets the job done when I’m bored. Could be better but hey, it’s something. Worth a look at jilipark app if you’re looking for a time killer.
Interesting take on maximizing returns! Seeing platforms like ph365 vip login focus on RTP (96.2% slots!) is smart for players. Mobile optimization-23% faster load times-is a huge plus too. Good analysis!
This is a foundational approach! For modern, high-scale APIs, while basic auth works, consider JWT or OAuth 2.0 for superior cross-domain resilience. Handling persistent sessions and sensitive data-whether it’s a bank account or a jollibee 777 slot-demands stateless tokens for true scalability. Great start!
The ‘instant-gratification’ angle is risky; always budget for volatility. Reviewing platforms like this requires financial discipline. Check out Olx 786 Vvip slot download first.
Honestly, I was skeptical about this whole ‘data-informed’ angle for gaming, but the focus on measurable signals is surprisingly insightful. Check out jollibee link; it frames things better than just listing slots!
Honestly, I expected more fluff. But the structure here actually makes sense for understanding the core mechanics. Checking out x game download helped clarify things; the platform details are solid.
My friend shared this link with me last weekend and I was hooked right away. Deposits work perfectly with local payment methods and the support team actually replies fast. It feels like playing with locals who really understand what we need on the field. br4455bet
The mobile experience on this one is absolutely fantastic and I can play anywhere without any glitches. I really enjoy the daily rewards and how the support team responds within minutes. It feels like a casino that truly values its users. Grab solcasinoapp
The lucky seven has always been my personal lucky charm and this platform truly lives up to its name. I appreciate how they balance nostalgia with fresh releases so the experience never gets stale. My routine has never been more consistent and I genuinely look forward to every session. a7777game
The registration process was dead simple and I was spinning within minutes. I really appreciate how transparent the bonus terms are and how quickly winnings hit my account. This is exactly what a modern gaming hub should look like. diwataplay88login
Loving the vibe here so much that I keep coming back every weekend. The interface feels clean and intuitive which makes finding new games a breeze. Plus the payment options are super flexible and match what we actually prefer using locally. Really appreciate the smooth operation. bdcd44
My friends keep telling me about this platform and I finally jumped in. The game variety is impressive and the customer support responds quickly on my phone. It feels like a genuine place to relax after a long day. joyabaji11
I was skeptical about online casinos until I tried play time game games. The secure setup and 24/7 support made me feel safe, which pleasantly surprised me. Highly recommended for anyone seeking a reliable community!
Had a bit of a lucky streak here yesterday! The login is seamless and the games load quickly without any lag. Visit 567jililogin if you want to try your luck.
The VIP rewards are actually worth it here. I feel valued as a player and the promotions are constantly updated. Check out rpvip5h5 for the best perks.
This setup sounds thorough; managing everything with kids is a juggling act! I’m curious about the structure you mentioned for Paldo Plus. Checking out paldo plus link might give me some perspective on regulated options.
This analysis nails the pre-flop read. Remember, even the best strategy needs a solid platform foundation; check out ok bet vip for seamless action. UX matters as much as the pot odds!
The login process is super quick and I haven’t faced any glitches so far. Great job on the optimization! 7sjilicomlogin
Super impressed with the bonus offers here. It really gives new players a great head start. I am spending a lot of my free time on daka88bet these days.
I’ve been using this app for a few weeks now and the interface is super smooth. Definitely one of the best experiences I’ve had lately. Check out 8999bdapp for more details.
OMG, this site is wild! 🤯 The description mentions mobile access, but checking out 999b apk seems way more direct for getting in fast. Gotta be careful though-stay safe online! ✨
[7569]3333bet অফিসিয়াল লগইন | সেরা অনলাইন ক্যাসিনো ও দ্রুত বিকাশ পেমেন্ট,3333bet অ্যাপ ডাউনলোড করে সেরা স্লট গেমের নিয়ম জানুন এবং দ্রুত বিকাশ পেমেন্ট সুবিধা উপভোগ করুন। আজই জয়েন করে আপনার যাত্রা শুরু করুন। visit: 3333bet
I appreciate how secure this site feels. My transactions are always processed quickly without any hassle. Big thanks to 666jililogin
The VIP bonuses here are actually worth it. I felt the difference in rewards compared to other sites. Give 25phwinvip a try if you want better perks.
I have tried many sites but this one actually delivers on its promises. The withdrawal process is fast and transparent. I am really happy with the results. Join vnm99win today.
Really happy with the customer support team here. They solved my deposit issue in minutes. It is hard to find such reliable service as bd09bed these days.
[4715]luckybaji লগইন এবং অ্যাপ ডাউনলোড | অনলাইন ক্যাসিনো গেম বাংলাদেশ,luckybaji login করার নিয়ম জানুন এবং অ্যাপ ডাউনলোড করুন। বিকাশ দিয়ে অনলাইন ক্যাসিনো পেমেন্ট ও স্লট গেম খেলার সহজ উপায় পেতে আজই ভিজিট করুন। visit: luckybaji
The risk assessment angle here is crucial; never treat a domain name as gospel. Always cross-reference local regulations before committing. For context on platform security, check out 1111 bet ডাউনলোড apk সর্বশেষ সংস্করণ uptodown. Stay smart out there!
Been playing here for a week now and the experience has been solid. Everything is transparent and the withdrawals are on point. Love 393bt
Hey guys, been trying out 8k8login lately. The site’s pretty straightforward, making it easy to jump right in. Worth checking out if you’re looking for something new! Check it out here: 8k8login
The variety of games is amazing. I spent the whole evening exploring different slots and won a decent amount. Great job ph178jili
Categories
Recent Posts
Mes sites
Archives