# @blinfo/authjs

> Javascript library, meant for browser use, to authenticate and authorize users against Björn Lundén Information

Latest version **0.1.5** (published 2021-04-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install @blinfo/authjs
pnpm add @blinfo/authjs
yarn add @blinfo/authjs
bun add @blinfo/authjs
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.5 |
| Published | 2021-04-26 |
| First published | 2018-03-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Jon-Erik Liw |
| Maintainers | xperjon, bergiusj, misvon, markushellstrom, pholmkvist, patrikolin, williamwallin, gustavholmsten, lovisasundin, fridalindgren |
| Keywords | javascript, blinfo, bl, oauth2 |

## Links

- npm: https://www.npmjs.com/package/@blinfo/authjs
- Repository: https://github.com/blinfo/BLAuthjs
- Homepage: https://github.com/blinfo/BLAuthjs#readme
- Issues: https://github.com/blinfo/BLAuthjs/issues
- npm.io page: https://npm.io/package/@blinfo/authjs

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 0.1.5 (latest) — 2021-04-26
- 0.1.4 — 2019-10-17
- 0.1.3 — 2018-10-19
- 0.1.2 — 2018-10-19
- 0.1.1 — 2018-04-18
- 0.1.0 — 2018-04-18
- 0.0.3 — 2018-04-05
- 0.0.2 — 2018-04-05
- 0.0.1 — 2018-03-29

## README

# 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 
```html
<script src="blauth-min.js" type="text/javascript"></script>
```

### Initialize
```javascript
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
```javascript
BLAuth.login((res) => {
    console.log('Logged in user:' + res.name);
});
```

### Response
```typescript
export interface BLUser {
    name: string;
    firstName: string;
    lastName: string;
    email: string;
    userName: string;
    authToken: string;
}
```

### Logout
```javascript
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.

```javascript
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.
```javascript
npm run build
```
4. Commit changes.
```javascript
git add .
git commit -m"made some changes."
```
5. Update version by typing the command:
```javascript
npm version [major|minor|patch]
```
6. Publish to npm registry.
```javascript
npm login
npm publish
```
7. Push commits AND tag to git.
```javascript
git push
git push origin vX.X.X
```
Need more help? https://docs.npmjs.com/getting-started/publishing-npm-packages

---
_Source: https://npm.io/package/@blinfo/authjs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
