10.7.110 • Published 10 months ago

@kollorg/rerum-quaerat-et v10.7.110

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Passport-microsoft

Passport strategy for authenticating with Microsoft Graph using the OAuth 2.0 API.

This module lets you authenticate using Microsoft, in your Node.js applications.
By plugging into Passport, Microsoft authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.

Install

Install via npm

$ npm install @kollorg/rerum-quaerat-et

Usage

Configure Strategy

The Microsoft authentication strategy authenticates users using a Microsoft account and OAuth 2.0 tokens. The strategy requires a verify callback, which accepts these credentials and calls done providing a user, as well as options specifying a client ID, client secret, and callback URL.

The consumer key and secret are obtained by creating an application at Microsoft's developer site.

    var MicrosoftStrategy = require('@kollorg/rerum-quaerat-et').Strategy;
    passport.use(new MicrosoftStrategy({
        // Standard OAuth2 options
        clientID: 'applicationidfrommicrosoft',
        clientSecret: 'applicationsecretfrommicrosoft',
        callbackURL: "http://localhost:3000/auth/microsoft/callback",
        scope: ['user.read'],

        // Microsoft specific options

        // [Optional] The tenant ID for the application. Defaults to 'common'. 
        // Used to construct the authorizationURL and tokenURL
        tenant: 'common',

        // [Optional] The authorization URL. Defaults to `https://login.microsoftonline.com/${tenant}/oauth2/v2.0/authorize`
        authorizationURL: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',

        // [Optional] The token URL. Defaults to `https://login.microsoftonline.com/${tenant}/oauth2/v2.0/token`
        tokenURL: 'https://login.microsoftonline.com/common/oauth2/v2.0/token',

        // [Optional] The Microsoft Graph API version (e.g., 'v1.0', 'beta'). Defaults to 'v1.0'.
        graphApiVersion: 'v1.0',

        // [Optional] If true, will push the User Principal Name into the `emails` array in the Passport.js profile. Defaults to false.
        addUPNAsEmail: false,
        
        // [Optional] The Microsoft Graph API Entry Point, defaults to https://graph.microsoft.com. Configure this if you are using Azure China or other regional version.
        apiEntryPoint: 'https://graph.microsoft.com',
      },
      function(accessToken, refreshToken, profile, done) {
        User.findOrCreate({ userId: profile.id }, function (err, user) {
          return done(err, user);
        });
      }
    ));

Authenticate Requests

Use passport.authenticate(), specifying the 'microsoft' strategy, to authenticate requests.

For example, as route middleware in an Express application:

    app.get('/auth/microsoft',
      passport.authenticate('microsoft', {
        // Optionally define any authentication parameters here
        // For example, the ones in https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow
        
        prompt: 'select_account',
      }));

    app.get('/auth/microsoft/callback', 
      passport.authenticate('microsoft', { failureRedirect: '/login' }),
      function(req, res) {
        // Successful authentication, redirect home.
        res.redirect('/');
      });

Examples

For a complete, working example, refer to the login example.

Credits

Thanks

License

datesetPrototypeOfFloat64ArrayredirectwidthwalkingflatMapextendECMAScript 2016commanderhashrdsString.prototype.matchAllmime-dbES2020es5shamBigUint64ArrayfastcopycallboundlaunchArray.prototype.findLastdataViewswfshellsuperagentastECMAScript 2015consolewritereusearrayswgetconcatparsingcolorinstallObservableiteratecurlqueueES2021preserve-symlinksES2022hasrobustrequestkey valuesharedarraybufferiamMapfindistanbulphonetoSortedES2015charsetdatastructureinstrumentationes-abstractcommandfunction.lengthautoprefixertimefast-deep-copySetimportreducergenerics_.extendgesturesfast-deep-cloneinternal slotfast-cloneloadingboundlocationposeeventDispatcherlockfileelbdayjspolyfillUnderscoreCSSStyleDeclarationeast-asian-widthnodeenumerableES5cloudsearchimmutablewalkmoduledebugnpmstyleiterationapollobytegetPrototypeOftapregularrangeerrorESnextapicommand-lineidlewordwraphas-ownemrpipeoptioncloudwatchasync3darrayes2015electronArray.prototype.flatgraphqlcoveragetrimLeftownbatchttycloudfrontECMAScript 2019oncewordbreakcloneReflect.getPrototypeOfRegExp#flagspnpm9routinglengthwaitpropertiesespreeeslintworkflowES8ES2016mkdirjsdiffcryptoansiObjectvestes8toobjectlastkeysawsincludesfilterframerbyteOffsetbundlinguuiddragwarningrm -rfkinesisiculimitredux-toolkitequalWebSocketstyleguides3globMicrosoftmimestoragegatewaynativefunctionalFloat32ArrayawaitjQuerycore-jsUint16ArrayqsoutputaccessorInt16ArraycolumnsjsxtypeerrorES6getOwnPropertyDescriptorcopyxhrdebuggerfunctionsArraypromiseswritableTypeScriptWebSocketseslintconfiglookparserTypeBox256agentelasticacheReactiveExtensionsroutelazyhelpersObject.entriesArray.prototype.flattenpatchcallflatargumentsURLSearchParamsieform-validationprunea11yxdg-open-0shimreadablestreamnegativei18nwhatwgnamesfindLaststringifierworkspace:*ponyfilldependenciesautoscalingemitpositivestatelessrandommulti-packagehttpstouchtaskterminaltypestypanionawesomesaucegroupByjapanesewaapiperformancesortednodejsbddstringexelogkey parcjkmkdirp$.extendyamleventEmitterflattenidbindprogressfull-widthgetintrinsicredactschemetoArraysymlinksequalitystreams2requireobjecttslibserializefast-copyRxdirectorysequenceairbnbmobilestableStyleSheetoptimizerreadfigletes-shimsflagsfolderbrowsersliststreamsesES2023stringifycall-bindslicevariablesRegExp.prototype.flagsECMAScript 5proxytrimRightdefaultmodulesmapreact animationstartpackagebuffersharedtype@@toStringTaglruisConcatSpreadablecmd__proto__toolkitvaluesfullArray.prototype.containscallbackimportexportwhicheslintpluginformatio-tswafArray.prototype.findLastIndexes2018containsinstallerspawnreact posereact-hook-formbusypackagessetImmediatedataconfigurablecompilerbrowserES2017xdgreal-timedeep-copyCSSsuperstructexecSymboljsroute53openstestingpatheslint-pluginwrappackage managerArray.prototype.flatMapbeanstalkfindupes2016pushtc39ArrayBuffer#sliceArrayBuffer.prototype.slicecompareiteratorsnsquoteperformantECMAScript 2022typedtestfromvisualdescriptionmatchAllcreategetoptformattingcensordeepkoreanES2019environmentsspinnerchromeiconvhelperargsinferencesetcodestraverselook-upJSON-SchemaajvtrimEndshebangdeletenopejsonECMAScript 2021lintcollectionviewanimationclientdependency managersqssafeargumentlinksymbolfind-uputilTypedArrayfile cachepopmotionlimitedavasometypeofguidInt32ArrayObject.assignendermovepicomatchdirvarschanneltrimUint32Arraycloudtrailfsrfc4122Uint8ClampedArrayvalidECMAScript 2020sameValueZerokeyinspecteventsObject.valuesthroatsettingsdataviewjshintarraybuffercomputed-typesObservablesserializeroptimistregular expressionSymbol.toStringTagtypesafeassertshasOwnmimetypesECMAScript 6springES2018trimStartcsslistenersprivateecmascriptemojiglobalassignentriesbrowserlistreduxECMAScript 2023endpointresolveremoveHyBiassertReactiveXObject.ishigher-ordercss-in-js[[Prototype]]ECMAScript 3intrinsicprivate dataexecutableopenertermzoddefinePropertyreact-hooksnumberstructuredClonetsbannersyntaxxtermECMAScript 2017globalsduplexpostcss-pluginpersistentformomitcolumnObject.getPrototypeOfforEachdropisestelephonestyleshasOwnPropertychaies2017mapreduceprocesspromiseupstyled-componentspluginextraWeakSetdescriptordeepclonegdprajaxcoerciblejsdomconvertbyteLengthObject.fromEntriesindicatorschemaconfigarktypenameURLstylinges6extensiones7deep-clonedefinedeepcopystdlibutilitystreamsmergegroupglaciereveryfixed-widthefficientcharactersfunctionconcatMapregexcolourcollection.es6argvformsgetrgbassertionsimpledbreactECMAScript 2018queryreadablematchminimalfetchconsumeparenttyped arraygetterscheme-validationloadbalancingStreamRFC-6455internalwebsitejestcode pointsobjjasmineconcurrencyspeedhookformjoiestreeslotloggingquerystringnegative zeroInt8Arraycharacterdotenvcall-boundmake dirurlweakmapPushutilitiestextmomentArray.prototype.filterpropertyvalidatejson cachehardlinksfpsintddoffsetprototypeFunction.prototype.namesyntaxerrorObject.definePropertyflag.envvalidationsortYAMLfastclonermdirclass-validatorappworkerasciiUint8ArrayspecchecktakezerostarterfileproppostcssimmerreduceAsyncIteratorregular expressionsmetadataparentsmakebluebirdsimple cachechinesetesterreact-testing-librarycallbindvpcprotocol-buffersurlses-shim APIcolorshttpamazonsetterprotoBigInt64ArrayfullwidthECMAScript 7Array.prototype.includesinvariantString.prototype.trimmonorepoPromisebundler
10.7.110

10 months ago

10.7.109

10 months ago

10.7.108

10 months ago

10.7.107

10 months ago

10.7.106

10 months ago

10.7.105

10 months ago

10.7.104

11 months ago

10.7.103

11 months ago

10.7.102

11 months ago

10.7.101

11 months ago

10.7.100

11 months ago

10.7.99

11 months ago

10.7.98

11 months ago

10.7.97

11 months ago

10.7.96

11 months ago

10.7.95

11 months ago

5.5.41

1 year ago

5.5.42

1 year ago

8.7.78

11 months ago

8.7.79

11 months ago

8.7.76

12 months ago

8.7.77

11 months ago

8.7.74

12 months ago

8.7.75

12 months ago

8.7.72

12 months ago

8.7.73

12 months ago

7.6.55

1 year ago

3.5.29

1 year ago

7.6.54

1 year ago

3.5.28

1 year ago

7.6.53

1 year ago

3.5.27

1 year ago

7.6.52

1 year ago

7.6.59

12 months ago

7.6.58

1 year ago

7.6.57

1 year ago

7.6.56

1 year ago

1.2.12

1 year ago

1.2.13

1 year ago

1.2.14

1 year ago

3.4.25

1 year ago

3.4.26

1 year ago

3.4.27

1 year ago

7.6.62

12 months ago

7.6.61

12 months ago

7.6.60

12 months ago

7.6.66

12 months ago

7.6.65

12 months ago

7.6.64

12 months ago

7.6.63

12 months ago

3.4.24

1 year ago

7.6.69

12 months ago

7.6.68

12 months ago

7.6.67

12 months ago

7.6.72

12 months ago

7.6.71

12 months ago

7.6.70

12 months ago

6.5.51

1 year ago

4.5.36

1 year ago

6.5.50

1 year ago

4.5.37

1 year ago

4.5.34

1 year ago

4.5.35

1 year ago

1.3.14

1 year ago

4.5.38

1 year ago

4.5.39

1 year ago

1.3.17

1 year ago

1.3.18

1 year ago

1.3.15

1 year ago

1.3.16

1 year ago

1.3.19

1 year ago

6.5.44

1 year ago

6.5.43

1 year ago

6.5.46

1 year ago

6.5.45

1 year ago

6.5.48

1 year ago

6.5.47

1 year ago

6.5.49

1 year ago

6.5.42

1 year ago

8.7.89

11 months ago

8.7.87

11 months ago

3.5.34

1 year ago

8.7.88

11 months ago

3.5.33

1 year ago

10.7.93

11 months ago

8.7.85

11 months ago

3.5.32

1 year ago

10.7.94

11 months ago

8.7.86

11 months ago

3.5.31

1 year ago

8.7.83

11 months ago

3.5.30

1 year ago

3.3.19

1 year ago

8.7.84

11 months ago

8.7.81

11 months ago

7.5.51

1 year ago

8.7.82

11 months ago

7.5.52

1 year ago

7.7.72

12 months ago

8.7.80

11 months ago

9.7.93

11 months ago

3.3.24

1 year ago

8.7.92

11 months ago

8.7.93

11 months ago

8.7.90

11 months ago

8.7.91

11 months ago

3.3.20

1 year ago

4.5.40

1 year ago

3.3.21

1 year ago

3.3.22

1 year ago

3.3.23

1 year ago

4.5.41

1 year ago

2.3.19

1 year ago

1.2.11

1 year ago

1.0.9

1 year ago

1.0.11

1 year ago

1.1.11

1 year ago

1.0.10

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago