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

ngx-authp-service

v1.0.8

Published

Auth Portal Angular service

Downloads

5

Readme

Auth Portal Service for Angular

The service works with caddy-auth-portal. It retrieves user data and, if necessary, redirects users to auth portal for authentication.

See also:

Installation

npm install ngx-authp-service --save

# or

yarn add ngx-authp-service

Usage

Add the auth portal service to your app.module.ts as a provider:

import { AUTHP_CONFIG, AuthPortalService, AuthPortalConfig } from 'ngx-authp-service';

const PROD_AUTHP_CONFIG: AuthPortalConfig = {
  baseUrl: 'https://auth.myfiosgateway.com:8443/',
};

@NgModule({
  ...
  providers: [
    {
      provide: AUTHP_CONFIG,
      useValue: PROD_AUTHP_CONFIG,
    },
    AuthPortalService
  ],
  ...
})

export class AppModule {
}

Then, import and inject it into a constructor:

import { AuthPortalService, UserData } from 'ngx-authp-service';

export class AppComponent implements OnInit {

  userData: UserData = {};

  constructor(
    private readonly authpService: AuthPortalService
  ) {
    this.authpService.whoami().subscribe(
      (data) => {
        this.userData = data;
        console.log(this.userData);
      },
      (error) => {
        console.error(error);
      }
    );
  }
}

The userData contains the information about the user. This data could be used to create a user badge (account, persona, etc.).

The raw field contains the raw response from whoami API endpoint.

export class UserData implements IUserData {
  id?: string;
  name?: string;
  email?: string;
  roles?: Array<string>;
  avatar?: string;
  origin?: string;
  raw?: object;

Caddy Configuration

The following Caddyfile configuration allows the Angular app running at https://authdb.myfiosgateway.com:8443 accessing https://auth.myfiosgateway.com/whoami API endpoint. If the configuration is not present, then default CORS policy would prevent the app accessing the auth portal.

auth.myfiosgateway.com {
    route {
        header {
            Access-Control-Allow-Origin "https://authdb.myfiosgateway.com:8443"
            Access-Control-Allow-Methods "POST, GET, OPTIONS, PUT, DELETE"
            Access-Control-Allow-Headers "Accept, Content-Type, Content-Length, Accept-Encoding, Authorization"
            Access-Control-Allow-Credentials true
        }
        authp {
            ...
        }
    }
}

Full Caddyfile:

{
        http_port 8080
        https_port 8443
        debug
}

auth.myfiosgateway.com {
        tls /home/greenpau/.local/tls/myfiosgateway/server.crt /home/greenpau/.local/tls/myfiosgateway/server.key
        route {
                header {
                        Access-Control-Allow-Origin "https://authdb.myfiosgateway.com:8443"
                        Access-Control-Allow-Methods "POST, GET, OPTIONS, PUT, DELETE"
                        Access-Control-Allow-Headers "Accept, Content-Type, Content-Length, Accept-Encoding, Authorization"
                        Access-Control-Allow-Credentials true
                }
                authp {
                        crypto default token lifetime 3600
                        crypto key sign-verify a3c6eeee16e4479e9f31786e30b3ebdc
                        backend local /home/greenpau/.local/caddy/users.json local
                        cookie domain myfiosgateway.com
                        ui {
                                links {
                                        "AuthDB" https://authdb.myfiosgateway.com:8443/ icon "las la-star"
                                        "My Identity" "/whoami" icon "las la-user"
                                }
                        }
                        transform user {
                                match origin local
                                action add role authp/user
                        }
                        transform user {
                                match origin local
                                match roles authp/user
                                ui link "Portal Settings" /settings icon "las la-cog"
                        }
                }
        }
}

authdb.myfiosgateway.com {
        tls /home/greenpau/.local/tls/myfiosgateway/server.crt /home/greenpau/.local/tls/myfiosgateway/server.key
        route {
                authorize {
                        primary yes
                        crypto key verify a3c6eeee16e4479e9f31786e30b3ebdc
                        set auth url https://auth.myfiosgateway.com:8443/
                        allow roles authp/admin authp/user
                        validate bearer header
                        inject headers with claims
                }
                file_server {
                        root /home/greenpau/angular/app
                }
        }
}