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

capacitor-msal

v0.2.1

Published

A Capacitor plugin that provides OAuth 2.0 authentication using the Microsoft Authentication Library

Downloads

19

Readme

Capacitor MSAL Plugin

This is an OAuth 2 client plugin for Capacitor. It uses the Microsoft Authentication Library (MSAL) to authenticate the user and acquire access tokens.

Installing

npm install capacitor-msal

Configuration

The capacitor-msal plugin needs to be imported into your application to register the plugin with Capacitor. In your app's entry point (such as main.ts in Angular applications), add the following line:

import 'capacitor-msal';

Once imported, the plugin needs to be initialized with app-specific values. In your initialization logic (such as APP_INTIALIZER in Angular), call the Msal.init() method. For example:

import { Plugins } from '@capacitor/core';
const { Msal } = Plugins;

await Msal.init({
	auth: {
		clientId: 'YOUR_CLIENT_ID'
	}
});

The init method accepts all configuration options from MSAL.js. Note that some options may not be supported on all platforms. The only required parameter is clientId.

Web

The Web platform is implemented as a passthrough to MSAL.js. No extra configuration is needed.

Electron

Once this plugin has been installed in your application, the Electron implementation needs to be installed into your Electron app as a dependency. Assuming your Electron app is one level below your root package.json, use the following command.

npm install ../node_modules/capacitor-msal/capacitor-msal-electron-<version>.tgz

The Electron plugin uses the native module keytar to securely store user refresh tokens. You will need a module that rebuilds native dependencies, such as electron-rebuild or electron-builder.

Next, the Electron implementation needs to be imported into your application as a preload script. This implementation is exported as ES Modules. The esm package is recommended to import this module.

Create a script (e.g. preload.js) with the following content.

require = require('esm')(module, {
	mainFields: ['module']
});

require('@capacitor/electron/dist/electron-bridge');
require('capacitor-msal-electron');

This will run in the renderer process to add Msal to the Capacitor Plugins proxy.

Add the newly created script to the main window as a preload script. For example,

mainWindow = new BrowserWindow({
	height: 920,
	width: 1600,
	show: false,
	webPreferences: {
		nodeIntegration: true,
		preload: path.join(__dirname, 'preload.js')
	}
});

Finally, the plugin needs to be added to the main process. A custom logger can be used to capture debug information from the plugin. The module electron-log is recommended.

const logger = require('electron-log');
const { CapacitorMsal } = require('capacitor-msal-electron');

const msal = new CapacitorMsal(logger);
msal.init();

The configuration file capacitor.config.json is required to use this plugin. The appId specified in this file will be used as the storage key for refresh tokens. Additionally,auth configuration options can be specified in this file. Options specified here will override the options specified in the init method. For example:

{
	"appId": "YOUR_APP_ID",
	"plugins": {
		"Msal": {
			"redirectUri": "https://login.microsoftonline.com/common/oauth2/nativeclient"
		}
	}
}

Proxy Settings

This plugin internally uses electron-fetch to access the token endpoint, and an Electron BrowserWindow is used to access the authorize endpoint. Both of these components use Chromium and its underlying network operations. As a result, this plugin will automatically use system-wide proxy settings without any additional configuration.

Android

Coming soon™

iOS

Coming soon™