Exciting news!Announcing our $4.6M Series Seed. Learn more
Socket
LoveBlogFAQ
Install
Log in

remix-auth-microsoft

Package Overview
Dependencies
2
Maintainers
1
Versions
3
Issues
File Explorer

Advanced tools

remix-auth-microsoft

The Microsoft strategy is used to authenticate users against a [Microsoft Identity](https://docs.microsoft.com/en-us/azure/active-directory/develop/) account. This can be a work/school account or a personal Microsoft account, like Skype, Xbox and Outlook.

    1.0.2latest

Version published
Maintainers
1
Yearly downloads
2,850

Weekly downloads

Changelog

Source

v1.0.2

Updated documentation, package author and links.

Readme

Source

MicrosoftStrategy

The Microsoft strategy is used to authenticate users against a Microsoft Identity account. This can be a work/school account or a personal Microsoft account, like Skype, Xbox and Outlook.com. It extends the OAuth2Strategy.

Supported runtimes

RuntimeHas Support
Node.js
Cloudflare

How to use

Create an OAuth application

Follow the steps on the Microsoft documentation to create a new App Registration. You should select Web as the platform, configure a Redirect URI and add a client secret.

If you want to support login with both personal Microsoft accounts and school/work accounts, you might need to configure the supported account types by editing the manifest file. Set `signInAudience` value to `MicrosoftADandPersonalMicrosoftAccount` to allow login also with personal accounts.

Be sure to copy the client secret, Redirect URI and the Application (client) ID (under Overview) because you will need them later.

Create the strategy instance

import { MicrosoftStrategy } from "remix-auth-microsoft"; let microsoftStrategy = new MicrosoftStrategy( { clientID: "YOUR_CLIENT_ID", clientSecret: "YOUR_CLIENT_SECRET", callbackURL: "https://example.com/auth/microsoft/callback", }, async ({ accessToken, extraParams, profile }) => { // Here you can fetch the user from database or return a user object based on profile // return {profile} // The returned object is stored in the session storage you are using by the authenticator // If you're using cookieSessionStorage, be aware that cookies have a size limit of 4kb // For example this won't work // return {accessToken, extraParams, profile} return User.findOrCreate({ email: profile.emails[0].value }); } ); authenticator.use(microsoftStrategy);

Setup your routes

// app/routes/login.tsx export default function Login() { return ( <Form action="/auth/microsoft" method="post"> <button>Login with Microsoft</button> </Form> ); } // app/routes/auth/microsoft.tsx import { ActionFunction, LoaderFunction } from "remix"; import { authenticator } from "~/auth.server"; export let loader: LoaderFunction = () => redirect("/login"); export let action: ActionFunction = ({ request }) => { return authenticator.authenticate("microsoft", request); }; // app/routes/auth/microsoft/callback.tsx import { ActionFunction, LoaderFunction } from "remix"; import { authenticator } from "~/auth.server"; export let loader: LoaderFunction = ({ request }) => { return authenticator.authenticate("microsoft", request, { successRedirect: "/dashboard", failureRedirect: "/login", }); };

Allow login only with accounts from a single organization (tenant)

If you want to allow login only for users from a single organization, you should add the tenant attribute to the configuration passed to MicrosoftStrategy. The value of tenant should be the Directory (tenant) ID found under Overview in your App Registration page.

You must also select Accounts in this organizational directory as Supported account types in your App Registration.

let microsoftStrategy = new MicrosoftStrategy( { clientID: "YOUR_CLIENT_ID", clientSecret: "YOUR_CLIENT_SECRET", callbackURL: "https://example.com/auth/microsoft/callback", tenant: "YOUR_TENANT_ID", }, async (accessToken, _, extraParams, profile) => { return User.findOrCreate({ email: profile.emails[0].value }); } );

Keywords

FAQs

What is remix-auth-microsoft?

The Microsoft strategy is used to authenticate users against a [Microsoft Identity](https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;azure&#x2F;active-directory&#x2F;develop&#x2F;) account. This can be a work&#x2F;school account or a personal Microsoft account, like Skype, Xbox and Outlook.

Is remix-auth-microsoft popular?

The npm package remix-auth-microsoft receives a total of 173 weekly downloads. As such, remix-auth-microsoft popularity was classified as not popular.

Is remix-auth-microsoft well maintained?

We found that remix-auth-microsoft demonstrated a healthy version release cadence and project activity. It has 1 open source maintainer collaborating on the project.

Last updated on 07 Feb 2022
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc