"Customizing the MsAdalAngular6Module setup on the fly - a step-by-step

In order to manage authentication in an Angular single page app, I am utilizing the microsoft adal wrapper available at https://github.com/manishrasrani/ms-adal-angular6.

Following the documentation, I configure all necessary options during compile time using the provided guidelines, which functions as intended.

@NgModule({
imports: [
    MsAdalAngular6Module.forRoot({
      tenant: '<YOUR TENANT>',<-------------------------------- ADD
      clientId: '<YOUR CLIENT / APP ID>',<--------------------- ADD
      redirectUri: window.location.origin,
      endpoints: { <------------------------------------------- ADD
        "https://localhost/Api/": "xxx-bae6-4760-b434-xxx",
        ---
        ---
      },
      navigateToLoginRequestUrl: false,
      cacheLocation: '<localStorage / sessionStorage>', <------ ADD
    }),
    ---
    ---
  ],
  ---
  ---
})

However, due to having an automated deployment pipeline with multiple environments (dev, test, prod, etc.) that require unique settings, I aim to apply these configurations at runtime. In other words, I prefer not to recompile for each environment I deploy to.

I have followed a helpful guide on loading settings from a json file at runtime: , which has been effective. The challenge now is how to incorporate values loaded this way into the MsAdalAngular6Module dynamically?

Answer №1

I encountered a similar issue and managed to resolve it by creating my own service that only includes the necessary component of the library, specifically the MsAdalAngular6Service. This way, I eliminated the need to import the entire MsAdalAngular6Module. The drawback is that I no longer have access to their AuthenticationGuard feature. However, this can be easily mitigated with a simple if-else statement based on their code.

The service I created looks like this:

import { Injectable } from '@angular/core';
import { MsAdalAngular6Service } from "microsoft-adal-angular6";
import { ConfigurationService } from "../configuration.service";

@Injectable( {
    providedIn: 'root'
} )
export class MsAdalAdapterService {

    private _adalSvc: MsAdalAngular6Service;

    constructor( private configService: ConfigurationService ) {
        this._adalSvc = new MsAdalAngular6Service( configService.adalConfig );
    }

    get adalSvc(): MsAdalAngular6Service {
        return this._adalSvc;
    }
}

Perhaps this solution will prove helpful to someone facing a similar challenge.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

User authentication on AngularJs is only initiated on the second interaction

My personally built AngularJs user authentication system is experiencing an unusual issue. While everything seems to be working fine - I can login, check access for specific pages, etc. - there is a strange behavior with the token authentication. It seems ...

Simpler and more sustainable methods for embedding HTML elements using a configuration file

Currently, I am devoting my time to a toy project that heavily relies on JavaScript. A key component of this project is a JSON file that contains configurations and input descriptions, along with range values and options. This JSON file enables me to easil ...

Encountering an unanticipated reference error while attempting to paste the data

// Modify the layout function document.addEventListener('DOMContentLoaded', function() { function modifyLayout(productId) { // Referencing the original card and detailed card const originalCard = document.querySelector(&ap ...

redux store is not synchronized with the state retrieved from redux logger using store().getState()

Dealing with the redux store in an SSR react app has been a challenge for me. Initially, everything was working smoothly - the initialState was created on the server and received by window.initialState on the client side. However, issues arose when I tried ...

Tips for avoiding duplicate checkboxes in AngularJS when labels are the same

In the code snippet above, there is an issue with the repeating checkboxes. The code generates checkboxes based on the data provided to filter a table, but sometimes it results in multiple checkboxes with the same label '123'. How can I modify th ...

Accessing clipboard contents upon button click using TypeScript

Seeking assistance with retrieving data from the clipboard in TypeScript after clicking on a button. Please provide guidance. Thank you! ...

Is it feasible to manipulate MySQL data with a React Native application?

I'm considering developing a React Native mobile app that can interact with a remote MySQL database (stored in the cloud and not on the device) without utilizing PHP for the backend. Is this feasible? ...

Tips on retrieving 'captureDate' from data points and dispatching it as a notification

Currently, I am working on adding a new feature to my discord bot that will allow it to collect the user's most recent gameclip. While I am able to gather all the necessary information in my console log, I am finding it challenging to figure out how t ...

extract element from a string with the help of jquery

When using AJAX to request HTML from a page, the process involves sending a request like this: function getHTML() { //set ajax call var options = { url: '/Controller', type: 'GET', d ...

Is there a way to display the button only when the user is able to enter an email in the input field?

I have a form for users to update their profile and a button to delete their account. I want the delete account button to only be visible if the user enters their email. $(document).ready(function() { var user_email = $('input[name="emp_email"]&a ...

Tips on attaining the desired CSS impact

I'm curious about the method used by the creators of carv.ai to achieve the text masking effect seen on the paragraph "Carv connects wirelessly ...". I'm aware of how background images can be masked on text. ...

Calculating time differences using moment.js

Trying to configure my clock to start at 5:00 and create a button that subtracts 5 seconds each time it's clicked, changing the display to 4:55. I've been struggling with this using JavaScript DateTime functionality and keep receiving the error m ...

The value returned by EntityRecognizer.resolveTime is considered as 'undefined'

In my bot's waterfall dialog, I am utilizing the LuisRecognizer.recognize() method to detect datetimeV2 entities and EntityRecognizer.resolveTime() to process the response. Here is an example of how I have implemented it: builder.LuisRecognizer.recog ...

Promise refused due to non-error caution

Error: h1.js:25 Warning: a promise encountered an issue with a non-error: [object String] I am unsure of the root cause of this error and would greatly appreciate any assistance in understanding it. I am currently learning about Promises and AJAX, so any ...

Setting up types for variables in Angular 2 componentsHere is an

I have a model that consists of multiple properties, and I aim to set all these properties with a default value of either empty or null. Here is an example of my Model: export class MyModel { name: string; jerseyNumber: number; etc... } In m ...

Utilizing jQuery to toggle containers based on link clicks

Hello everyone, I'm having trouble getting this code to work. I have a set of 4 links and I need to display one div container for 3 of them, and another for the remaining 1 link, switching back and forth. Any suggestions? <div class="content activ ...

Guide to transforming Excel formulas into JavaScript

In my Excel sheet, I have the following formula: =IF($F6=0,"",IF(I6=0,"",$F6/I6)) where F6=7000 and I6 is empty. The Excel result is displaying no data for the formula. Now, I need to convert this formula into JavaScript. function AB6(F6) { var ...

Exploring hierarchical information within a JSON response from a Wiki API

As a newcomer to this field, I am currently exploring ways to access Wikipedia's API for extracting the value of "extract" and adding it to an HTML element dynamically. The challenge lies in the fact that the information is subject to change based on ...

Collaborating and monitoring data between controllers

A unique challenge has arisen as we implement a tree-style navigation element that must communicate with other directives/controllers. The main objectives are: Keep track of the current selection, Detect when the row selection changes. The task at hand ...

Acquire multiple instances of NestJs dependencies using dependency injection within a single class

Below is a class called Product @Injectable() export class Product { brand: string; } I am injecting the Product class into ProductService export class ProductService { constructor(private readonly product: Product) {} update(products) { ...