Coder Social home page Coder Social logo

authenticate.js's Introduction

AuthenticateJS

AuthenticateJS is a simple angular library for handling security

Installation

To use this library you should have a server application that handles authentication with sessions and it should have a login api that uses a username and password parameters from request body, a logout url and an api to get the current loggedin user with its credentials.

  • Install the library
bower install authenticateJS
  • load the library
<script src="js/angular.min.js"></script>
<script src="js/angular-route.min.js"></script>
<script src="js/authenticate.js"></script>
  • copy the library partials to your public directory to the folder partials/authenticateJS

  • add it to your dependencies

angular.module('myapp', ['authenticate.js']);
  • configure
angular.module('myapp').config(['AuthenticateJSProvider', function (AuthenticateJSProvider) {

    AuthenticateJSProvider.setConfig({
        host: 'api/',                  // your base api url
        loginUrl: 'auth/login',        // login api url
        logoutUrl: 'auth/logout',      // logout api url
        loggedinUrl: 'auth/loggedin',  // api to get the user profile and roles

        unauthorizedPage: '/unauthorized',  // url (frontend) of the unauthorized page
        targetPage: '/dashboard',           // url (frontend) of the target page on login success
        loginPage: '/login'                 // url (frontend) of the login page
    });

}]);

Usage

  • In your login page, include the login form like this
<div authenticate-login-form></div>

You can override the default login form template like this

<div authenticate-login-form template-url="mypartial.html"></div>
  • add a security attribute to your routes

    • a false value means that the route is not protected,
    • a true value means, you have to be loggedin to access this route,
    • other custom string can be used to indicate that a user role is required to access this route (the string represent the role that have to be found in user.roles)
  • you can call AuthenticateJS.logout(); to loggout

  • you cas use AuthenticateJS.getLoggedinUser() to get the current loggedin user

authenticate.js's People

Contributors

toamitkumar avatar youknowriad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

authenticate.js's Issues

loggedin?

Could you please tell us how this method work ?
It is called on the first load too.

vincent

getLoggedinUser()

How to use this method AuthenticateJS.getLoggedinUser()
to display a link to login if the user is not logged
and a lonk to logout if the user is logged
like a switch ?

thanks

Ui-Router

Hi

Do you have plan to support ui-router ?

Thanks

API suggestions

Hi all,

I'm trying to get a simple authentication in my app and this seems to be a decent implementation. But i'm wondering on which API's you guys suggest to use with this module. I'm currently running a php server on which i retrieve some JSONs, so i think it would be nice to protect that too but i'm currently open for suggestions.

Add LICENSE to the project

Hello, what kind of license have this project?
It could be interesting to add any type of open source license

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.