npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@demoiselle/security

v3.0.1

Published

Demoiselle Frontend security module

Downloads

83

Readme

Security Module

Compatibilidade com o Angular:

  • 3.x para Angular 6
  • 2.x para Angular 5
  • 1.x para Angular 2 e 4

O módulo Security disponibiliza os seguintes serviços/componentes:

  • AuthService: Provê serviços de autenticação e reToken;
  • TokenService: Provê serviços de armazenamento e acesso ao token de segurança, assim como verificação se o usuário está autorizado (baseado em roles);
  • AuthGuard: Serviço que intercepta acesso as rotas e redireciona para a página de login caso a autenticação seja requerida;
  • Diretivas de segurança: Diretivas para exibição de conteúdo de acordo com autenticação/autorização;

Instalaçao

npm install --save @demoiselle/security

Utilização e configuração

https://demoiselle.gitbooks.io/documentacao-frontend/content/modulo-security/configurando-sua-aplicacao.html

Exemplo - Login

Utilizando o serviço para realizar o login:

import { AuthService } from '@angular/security';

constructor(private authService: AuthService) {}

// ...código resumido

this.authService.login(this.user)
    .subscribe(res => {
        // Usuário autenticado!
        console.log('Token:', res);
    });

Configuração

A classe AuthOptions permite a configuração do módulo Security. As seguintes propriedades podem ser configuradas:

  • authEndpointUrl: (Obrigatório) string com o endereço do serviço que irá realizar a autenticação;
  • loginResourcePath: string com o caminho do recurso que responde pela operação de login no backend;
  • tokenKey : chave localstorage para acesso ao token jwt;
  • loginRoute: string com a rota que apresenta a tela de login na aplicação;
  • doReToken: informa se o re-token deve ser realizado automaticamente antes da expiração do token;
  • tokenGetter: função javascript para obtenção do token;
  • tokenSetter: função javascript para alteração do valor do token;
  • tokenRemover: função javascript para remoção do token;

Exemplo de configuração


    // Demoiselle AuthOptions, using default values except api endpoint
    export class MyAuthOptions extends AuthOptions {
       authEndpointUrl = environment.apiUrl;
    }
    
    // ...
    providers: [
        // ...
        {
          provide: AuthOptions,
          useClass: MyAuthOptions
        },
    ]

ReToken

O ReToken é utilizado para renovar o token JWT automaticamente antes de sua expiração. O intervalo de ReToken é calculado a partir das informações do token (atributos 'exp' e 'iat'). Caso não seja ativado, após a expiração do Token o usuário será redirecionado para a tela de login da aplicação.

Para informações sobre configuração e implementação de segurança com Token JWT no backend Demoiselle consulte a Documentação JWT Backend.

Para ativar, use a propriedade doReToken na configuração do AuthServiceProvider:

{
    ...
    doReToken: true,
    ...
}

AuthGuard

Adicione o AuthGuard na configuração de rotas para exigir autenticação. Para isso use o atributo canActivate:

import { AuthGuard } from '@demoiselle/security';

// ...código resumido
{ 
    path: 'usuario/edit/:id',
    canActivate: [AuthGuard],
    component: UsuarioEditComponent 
}

Utilização das diretivas de segurança

  1. Importe o módulo de segurança em sua aplicação;
  2. Use as diretivas em seus templates HTML.
// Importe #1
import { SecurityModule } from '@demoiselle/security';

@NgModule({
    // Importe #2
    imports: [SecurityModule],

    // ...código resumido
})
<!-- Use no seu template HTML -->
<div id="sidebar-menu" *dmlHasRoles="['ADMINISTRATOR']">