angular-basic-auth

WebJar for angular-basic-auth

License

License

MIT
Categories

Categories

Angular User Interface Web Frameworks
GroupId

GroupId

org.webjars.bower
ArtifactId

ArtifactId

angular-basic-auth
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

angular-basic-auth
WebJar for angular-basic-auth
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/xelita/angular-basic-auth

Download angular-basic-auth

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.bower/angular-basic-auth/ -->
<dependency>
    <groupId>org.webjars.bower</groupId>
    <artifactId>angular-basic-auth</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.bower/angular-basic-auth/
implementation 'org.webjars.bower:angular-basic-auth:1.0.0'
// https://jarcasting.com/artifacts/org.webjars.bower/angular-basic-auth/
implementation ("org.webjars.bower:angular-basic-auth:1.0.0")
'org.webjars.bower:angular-basic-auth:jar:1.0.0'
<dependency org="org.webjars.bower" name="angular-basic-auth" rev="1.0.0">
  <artifact name="angular-basic-auth" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.bower', module='angular-basic-auth', version='1.0.0')
)
libraryDependencies += "org.webjars.bower" % "angular-basic-auth" % "1.0.0"
[org.webjars.bower/angular-basic-auth "1.0.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.webjars.bower : angular jar [1.2.3,1.3)
org.webjars.bower » angular-base64-codec jar [1.0.0,1.1)

Project Modules

There are no modules declared in this project.

Bower version Build Status

[angular-basic-auth]

Basic authentication for AngularJS applications.

IMPORTANT: This library relies on angular-basic-auth-codec library (http://github.com/xelita/angular-basic-auth) to encode /decode data to/from basic-auth.

Install

Using Bower

bower install angular-basic-auth

Quick start

  • Include the library in your application.
<script src="js/angular-basic-auth.js"></script>

or use the minified version:

<script src="js/angular-basic-auth.min.js"></script>
  • Add the module basicAuthModule as a dependency to your app module:
var myapp = angular.module('myapp', ['basicAuthModule']);
  • Use the basicAuthService as dependency and call basicAuthService API:

Generating an authorization header based on given username and password

$scope.testGenerateAuthorizationHeader = function() {
    basicAuthService.generateAuthorizationHeader('john', this is my password'); // return 'Basic am9obg==:dGhpcyBpcyBteSBwYXNzd29yZA=='
};

Logging a user in

The logging process is made with a post request on a given url. Sent data (auth data) is a json object that should contain at least a username and a password. These last are controlled by the backend service. Of course, you can add more information in the authData object.

e.g

{
   username: 'john',
   password: 'this is my password',
   extra: 'obama'
}

During the call, you can provide optional callback that will allow you to interact with potential data coming from the remote server. e.g.

  • Display data in the view
  • Store these data in a service for a further usage
  • etc...

A sample call could be:

$scope.testLogin = function() {
   var authData = {username: 'john', password: 'this is my password'};
   
   var successCB = function(response) {
       // Work with extra data coming from the remote server
       $scope.generatedKey = response.data.generatedKey;
   };
   
   var failureCB = function(error) {
       $scope.status = 'ERROR';
   };
   
   basicAuthService.login('http://www.mysite.com/login', authData, successCB, failureCB);
};

If the logging step succeeds, then further HTTP request will be made using a 'Authorization' header (computed by the given username and password). e.g. request with 'Authorization' header equals to 'Basic am9obg==:dGhpcyBpcyBteSBwYXNzd29yZA=='.

Logging a user out

The logout process is made with a post request on a given url.

During the call, you can provide optional callback that will allow you to interact with potential data coming from the remote server. e.g.

  • Display data in the view
  • Store these data in a service for a further usage
  • etc...
   var successCB = function(response) {
       $scope.generatedKey = '';
   };
   
   var failureCB = function(error) {
       $scope.status = 'ERROR';
   };
    
   $scope.testLogout = function() {
       basicAuthService.logout('http://www.mysite.com/login', successCB, failureCB);
   };

If the logout step succeeds, then further HTTP request will be made using a cleaned 'Authorization' header ('Basic ').

Developers

Clone the repo, git clone git://github.com/xelita/angular-basic-auth.git. The project is tested with jasmine running on karma.

$ npm install
$ bower install
$ npm test

Contributing

Please submit all pull requests the against master branch. If your unit test contains JavaScript patches or features, you should include relevant unit tests. Thanks!

Copyright and license

The MIT License (MIT)

Copyright (c) 2014 The Enlightened Developer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Versions

Version
1.0.0