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

msal-community-solid

v0.2.1

Published

A Solid.js SPA library for the Microsoft Identity Platform implemented as a wrapper around @azure/msal-browser.

Downloads

806

Readme

msal-community-solid

The msal-community-solid package provides an authentication solution for Solid.js single-page applications (SPAs) based on the Microsoft Identity Platform. The platform supports sign-in through Azure Active Directory, allowing sign-in with Microsoft accounts as well as Azure AD accounts; and Azure Active Directory B2C, which is a white-labeled and highly customizable authentication solution supporting local as well as social accounts.

Experimental Status

This package is currently experimental, meaning all APIs are subject to change. This is to simplify the process of improving the APIs based on community needs and feedback.

Suggestions and feedback on this package are welcome and encouraged—please raise a GitHub issue to provide your input.

msal-browser

This package functions as a wrapper around the msal-browser library, and the documentation for the library will apply here as well.

Basic Usage

Installation

Install the packages msal-community-solid and @azure/msal-browser.

# with pnpm
pnpm add msal-community-solid @azure/msal-browser

MSAL Instance Setup

Create a PublicClientApplication (see the documentation for msal-browser for more details on how to do that):

import { Configuration, IPublicClientApplication, PublicClientApplication } from "@azure/msal-browser";

const msalConfig: Configuration = {
    auth: {
        clientId: "MY_CLIENT_ID",
        authority: "https://login.microsoftonline.com/common/",
        redirectUri: "https://my-application.example.com/"
    },
    cache: {
        cacheLocation: "localStorage"
    }
};

const msalInstance: IPublicClientApplication = new PublicClientApplication(msalConfig);

Refer to the documentation for configuring msal-browser to see how you can configure your application. In addition, refer to msal-browser's documentation for working with Azure AD B2C if you want to use Azure AD B2C.

You will need to register your app using the Azure Portal (or with an alternate way of accessing Azure such as the CLI).

MSAL Provider

Set up the MSAL provider passing it the MSAL instance you created. All components that need reactive access to authentication state should be descendants of the MSAL provider.

import { MsalProvider } from "msal-community-solid";

const MyApp: Component = () => {
    return (
        <MsalProvider instance={msalInstance}>
            <MyChild />
        </MsalProvider>
    );
};

The MSAL provider will handle initializing the MSAL instance. It will also handle incoming replies from OIDC/OAuth2 flows.

Usage

Within a child component of the provider, you can access the MSAL context with useMsal.

It returns a tuple composed of a read context and a write context.

The read context allows you to access MSAL's current interaction status, a list of all available accounts, and the currently active account. It is a Solid.js store, and you should follow the same rules as you would with other stores to avoid losing reactivity.

The write context allows you to access the actual MSAL instance and logger. Despite its name, you can still read from it—but keep in mind that reads here will not be reactive.

You can also use the useIsAuthenticated consumer to determine whether the user is authenticated or not, and the AuthenticatedTemplate and UnauthenticateTemplate components to conditionally display their children depending on user's authentication status.

Logging In, Out and Acquiring Tokens

You can directly use the MSAL instance (available in the write context returned by useMsal) to log users in and out, and to acquire tokens.

Further Documentation

The public API of this library includes documentation comments which can be referred to for more information.