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

cidaas-angular-sdk

v1.2.2

Published

## Table of Contents - [Overview](#overview) - [Prerequisites](#prerequisites) - [Installation](#installation) - [Configuration](#configuration) - [Usage](#usage) - [Authentication](#authentication) - [Checking if user is authenticated Information](#c

Downloads

37

Readme

cidaas-angular-sdk

Table of Contents

Overview

The cidaas-angular-sdk is a comprehensive software development kit that facilitates seamless integration of cidaas authentication and authorization services into your Angular applications. It provides a set of tools and interfaces to implement secure user authentication, manage tokens, and access user information with ease.

Prerequisites

Before you begin, ensure you have met the following requirements:

  • Node.js (version 16.x or higher)
  • Angular CLI (version 16.x or higher)
  • A cidaas account and a registered application

Installation

To install the cidaas-angular-sdk, run the following command in your project directory:

npm install cidaas-angular-sdk

Configuration

Import the WebAuthModule in your app.module.ts:

import { WebAuthModule } from 'cidaas-angular-sdk';

@NgModule({
  imports: [
    // ... other imports
    WebAuthModule.forRoot({
      client_id: 'YOUR_CLIENT_ID',
      redirect_uri: 'YOUR_REDIRECT_URI',
      authority: 'YOUR_CIDAAS_BASE_URL',
      skipRedirectCheck: false,
      post_logout_redirect_uri: 'YOUR_POST_LOGOUT_REDIRECT_URI'
    }),
  ],
  // ... rest of your NgModule configuration
})
export class AppModule { }

Replace YOUR_CLIENT_ID, YOUR_REDIRECT_URI, YOUR_CIDAAS_BASE_URL and YOUR_POST_LOGOUT_REDIRECT_URI with your actual cidaas configuration.

Usage

Authentication

To authenticate a user:

import { WebAuthService } from 'cidaas-angular-sdk';

class ProfileComponent {
  constructor(
    public authService: WebAuthService
  ) {


  }

  login() {
    this.authService.loginWithBrowser() // Login with browser
  }
}

Checking if user is authenticated Information

After successful authentication:

this.authService.isAuthenticated$.subscribe(
  authenticated => {
    console.log('Authenticated:', authenticated); //boolean
  },
  error => {
    console.error('Error fetching user info:', error);
  }
);

Guard routes with authenticated user

Allow routes to be accessed by only authenticated users.


import { authGuardFn } from 'cidaas-angular-sdk';

const routes: Routes = [
  {
    path: '<route>',
    component: 'COMPONENT',
    canActivate: [authGuardFn] // import authGuardFn
  },
  {
    path: 'profile-lazy',
    loadChildren: () => import('LAZY_MODULE_PATH')
      .then(m => 'm.MODULE_NAME'),
    canActivate: [authGuardFn] // import authGuardFn
  }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

Replace <route>, COMPONENT with route, component of your choice. If you need to extend the guard logic and compose it with other guard implementations

Getting User Information

After successful authentication:

this.authService.user$.subscribe(
  userInfo => {
    console.log('User Info:', userInfo);
  },
  error => {
    console.error('Error fetching user info:', error);
  }
);

Logout

To log out the user:

this.authService.logout();

API Reference

WebAuthService

The main service for interacting with cidaas authentication.

Methods:

  • loginWithBrowser(signInOptions?: SignInRedirectArgs): Observable<void>: Initiates the login process
  • loginCallback(paramsToRemove?: string[]): Observable<User | null>: Handle logout callback, pass on options to remove the url arguments. Returns Observable<User | null>
  • popupSignIn(options?: SignInPopupArgs): Observable<User>: Initiates the login process with popup
  • popupSignInCallback(url?: string): Observable<User> : Handle popupSignInCallback and returns Observable
  • logout(): Observable<void>: Initiates the logout process
  • getUserInfo(): Observable<User>: Retrieves the authenticated user's information as observable
  • getToken(): Observable<string | null>: Returns the current access token as observable
  • logout(options?: SignoutRedirectArgs, useDirect: boolean = false): Observable<void>: Logout the authenticated user