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
- Clone repo.
- Make changes.
- Build.
npm run build
- Commit changes.
git add .
git commit -m"made some changes."
- Update version by typing the command:
npm version [major|minor|patch]
- Publish to npm registry.
npm login
npm publish
- 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