Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

A javascript library, meant for browser use, to authenticate and authorize users against Björn Lundén Information.

Notifications You must be signed in to change notification settings

blinfo/BLAuthjs

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blinfo Authjs

A javascript library, meant for browser use, to authenticate and authorize users against Björn Lundén Information.

Installation

npm install @blinfo/authjs

For vanilla javascript projects

Load script

<script src="blauth-min.js" type="text/javascript"></script>

Initialize

BLAuth.init({ clientId: 'your-client-id', redirectURI: 'your-redirect-url', scopes: ['requested-scope']});
BLAuth.getLoginStatus((res) => {
    console.log('Logged in user:' + res.name);
});

Init option params

  • clientId: string - The id of registrated client at BL.
  • redirectURI: string - Registrated redirect URL.
  • scopes: stringarray (optional) - Requested scopes. If no scope is provided, then the id scope USER_IDENTITY will be used.
  • returnURL: string (optional) - Return URL.
  • width: number (optional) - Width of login popup.
  • height: number (optional) - Height of login popup.
  • env: string (optional) - Environment (dev, test or empty for production).

Login

BLAuth.login((res) => {
    console.log('Logged in user:' + res.name);
});

Response

export interface BLUser {
    name: string;
    firstName: string;
    lastName: string;
    email: string;
    userName: string;
    authToken: string;
}

Logout

BLAuth.logout(res => {
    console.log("User logged out");
});

For Angular projects

Create a service and make sure the service is loaded at the redirect url.

import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Observable } from 'rxjs/Observable';
import * as blauth from '@blinfo/authjs';

@Injectable()
export class Auth2Service {

    private _authState: BehaviorSubject<blauth.BLUser> = new BehaviorSubject(null);

    get authState(): Observable<blauth.BLUser> {
        return this._authState.asObservable();
    }
    constructor() {
        blauth.init({ clientId: 'your-client-id', redirectURI: 'your-redirect-url', scope: 'requested-scope' });
        blauth.getLoginStatus((user: blauth.BLUser) => {
            this._authState.next(user);
        });
    }

    login() {
        blauth.login((user: blauth.BLUser) => {
            this._authState.next(user);
        });
    }
    logout() {
        blauth.logout(() => {
            this._authState.next(null);
        });
    }
}

How to build and publish

  1. Clone repo.
  2. Make changes.
  3. Build.
npm run build
  1. Commit changes.
git add .
git commit -m"made some changes."
  1. Update version by typing the command:
npm version [major|minor|patch]
  1. Publish to npm registry.
npm login
npm publish
  1. Push commits AND tag to git.
git push
git push origin vX.X.X

Need more help? https://docs.npmjs.com/getting-started/publishing-npm-packages

About

A javascript library, meant for browser use, to authenticate and authorize users against Björn Lundén Information.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  
Morty Proxy This is a proxified and sanitized view of the page, visit original site.