0.1.5 • Published 5 months ago

@blinfo/authjs v0.1.5

Weekly downloads
3
License
ISC
Repository
github
Last release
5 months ago

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

0.1.5

5 months ago

0.1.4

2 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago