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

@aeroline_1025/angular-mobilesso

v1.1.2

Published

Manage the oidc, as Authorization Code mode, for MobileSSO

Downloads

22

Readme

Angular MobileSSO

Install the componant

Run npm install @aeroline_1025/angular-mobilesso to install the package on your project.

Configure Module

On the file app.modules.ts, add the MobileSSO Module

import { MobileSsoModule } from  '@aeroline_1025/angular-mobilesso';

@NgModule({
   imports: [
      MobileSsoModule
   ]
})

Environment Configuration

Use the environment configuration file to pass the mandatory paramters to use the MobileSSO:

  • issuer : issuer defined by the MobileSSO
  • scope: Scope define for the project by MobileSSO, to retreive the Access Token
  • clientId: Client ID defined by MobileSSO to defined which clinet we are
  • redirectUrl: Url declared on MobileSSO and associated to our ClientID, It will be the Url redirect by the mobile SSO to send Authorization Code (as Query parameter)
  • autoRefreshAccessToken (boolean): Define if the Access Token is automatically updated by the Id Token, when it nearly expire

This is an example :

export const environment = {
	issuer:  '<URL Issuer (FedBroker)>',
	scope:  'SCO_<Project Scope>',
	clientId:  'CLI_<Project Client>',
	redirectUrl:  '<URL to redirect by MobileSSO>/',
	autoRefreshAccessToken:  true
}

There are the default properties to use to instanciate a new AuthConfigMobileSSO used by the componant angular-mobilsso

How to authenticate

The only thing to do is to :

  • Define the AuthConfigMobileSSO through the environment file
  • Import the Mobile SSO Module on the app module
  • Call the methode authenticate(...) from the class MobileSsoHelper

This is the class to import and the signature of the method to use :

import { MobileSsoHelper } from  '@aeroline_1025/angular-mobilesso';

public authenticate(config: AuthConfigMobileSSO,
                    loginServiceUrl: string,
                    showLogInfo = false,
                    @Optional() callback:  any):  void {}
  • config: AuthConfigMobileSSO parameters
  • loginServiceUrl : Url to our own service login to validate the Access Token retreived and validate login (and / or generate internal JWT application token)
  • showLogInfo: Define if we display logs INFO or not
  • callback: is an object with at least the method what to do more when Access Token is received. It is optionnal : applyToken(data: TokenResponse): void;

Exemple of applyToken method :

    /**
     * Apply token from internal zone
     * @param data Token response
     */
    applyToken(data: TokenResponse): void {
        if (window.opener) {
            window.opener.my.app.applyTokenFromOutside(data);
        } else {
            localStorage.setItem(this.KeyTokenStorageName, JSON.stringify(data));
            this.setCurrentTokenResponse(data); // It is a custom method to store some date information
            this.router.navigate(['']);
          }
    }

Where to authenticate

The authentication has to be done on a Interceptor, where the method will be called to authenticate through the MobileSSO Helper

Exemple of interceptor : In this example this.userService.Authenticate(true); is a custom method on a user service custom where the method this.mobileSsoHelper.authenticate(GlobalConfiguration.getMobileSsoConfig(), this.loginServiceUrl true, this.callback); is called

/**
* Interception method
* @param  request Http request
* @param  next next action
*/
public  intercept (request:  HttpRequest<any>, next:  HttpHandler): Observable<HttpEvent<any>> {
   this.Logger.info(`Process to request : ${request.url}`);
   if (request.url  !==  this.loginServiceUrl) {
       // Normal request (add current token)
       request  =  this.addTokenHeaders(request);
       if (this.userService.isTokenExpired()) {
           this.Logger.info('Token is expired, ask a new token');
           **this.userService.Authenticate(true)**;
      } else {
           // Execute request
           return  next.handle(request)
                               .pipe(
                                  map(res  =>  res),
                                  catchError((err, caught) => {
                                        if (err  instanceof  RedoException) {
                                            throw  err;
                                        }
                                        if (err  instanceof  HttpErrorResponse) {
                                              this.Logger.warning('Error in HTTP interceptor');
                                              const  jsonParseError  =  'Http failure during parsing for';
                                              const  matches  =  err.message.match(new  RegExp(jsonParseError, 'ig'));
                                             // return of(null);
                                             if (err.status  ===  200  &&  matches.length  ===  1) {
                                                  // return obs that completes;
                                                  this.Logger.info('Skip http failure for parsing, response type is not JSON however the format seems good.');
                                                  throw(err.error.text);
                                            } else {
                                                  if (err.status  ===  401) {
                                                      // Authentication error
                                                      this.Logger.error(`Authentication error : ${err.message}`);
                                                      **this.userService.Authenticate(true)**;
                                                      throw  new  AutorizationException();
                                                  } else {
                                                       this.Logger.error(`Application communication error (code ${err.status}) : ${err.message}`);
                                                       throw(err);
                                                  }
                                            }
                                       }
                                       return  caught;
                                  }));
         }
    }
    return  next.handle(request);
}