@blinfo/authjs
TypeScript icon, indicating that this package has built-in type declarations

0.1.5 • Public • Published

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

Package Sidebar

Install

npm i @blinfo/authjs

Weekly Downloads

1

Version

0.1.5

License

ISC

Unpacked Size

13.7 kB

Total Files

5

Last publish

Collaborators

  • lisahag
  • hugohaggmark
  • alexandraonegard
  • xperjon
  • misvon
  • markushellstrom
  • pholmkvist
  • williamwallin
  • lovisasundin
  • fridalindgren