0.0.32 • Published 2 years ago

@piges/auth-angular v0.0.32

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

PigesAngularAuth

Library for use security funcionality of piges PaaS in angular

Installation

npm i @piges/auth-angular

Usage

Import and configure module

// myApp.module.ts

import { PigesAuthModule, PIGES_CONFIG, IPigesConfig } from '@piges/auth-angular';

const pigesConfig = {
	clientId: '-----------------------',
	redirectUrl: 'https://your-app-url.tld/piges/auth/callback',
	//idp_identifier: '',
	//clientSecret: '',
}

@NgModule({
  imports: [
    ...
    PigesAuthModule
  ],
  providers: [
    { 
      provide: PIGES_CONFIG, 
      useValue: { pigesConfig } 
    }
  ],
})
export class MyAppModule { }

Use PigesAuthGuard for protect your route

// myApp.route.ts

import { PigesAuthGuard } from '@piges/auth-angular';

const routes: Routes = [
	{
		path: 'secure-page',
		canActivate : [
			PigesAuthGuard
		],
		component: SecureComponent,
	},
	...
];

Manage the login redirect and login callback with route

// myApp.route.ts

import { PigesAuthLoginComponent, PigesAuthCallbackComponent } from '@piges/auth-angular';

const routes: Routes = [
	{
		path: 'piges/auth',
		children: [
			{
				path: 'login',
				component: PigesAuthLoginComponent,
			},
			{
				path: 'callback',
				component: PigesAuthCallbackComponent
			},
		]
	},
	...
];

Get user info in your component

// my.component.ts

import { PigesAuthService } from '@piges/auth-angular';

export class MyComponent {
	constructor(
		private pigesAuthService: PigesAuthService,
	) {}

	userInfo: any = {};

	ngOnInit(): void {
		this.loadUser();
	}

	async loadUser() {
		this.userInfo = await this.pigesAuthService.getUser();
	}

}

License

MIT

0.0.32

2 years ago

0.0.20

2 years ago

0.0.21

2 years ago

0.0.22

2 years ago

0.0.23

2 years ago

0.0.24

2 years ago

0.0.25

2 years ago

0.0.18

2 years ago

0.0.19

2 years ago

0.0.30

2 years ago

0.0.31

2 years ago

0.0.26

2 years ago

0.0.27

2 years ago

0.0.28

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago