WSFED/SAMLP/OIDC/Bearer Passport strategies for Azure Active Directory
passport-azure-ad is a collection of Passport Strategies to help you integrate with Azure Active Ditectory. It includes OpenID Connect, WS-Federation, and SAML-P authentication and authorization. These providers let you integrate your Node app with Microsoft Azure AD so you can use its many features, including web single sign-on (WebSSO), Endpoint Protection with OAuth, and JWT token issuance and validation.
$ npm install passport-azure-ad
This sample uses the OAuth2Bearer Strategy:
// We pass these options in to the ODICBearerStrategy.var options =// The URL of the metadata document for your app. We will put the keys for token validation from the URL found in the jwks_uri tag of the in the metadata.identityMetadata: configcredsidentityMetadataissuer: configcredsissueraudience: configcredsaudience;var bearerStrategy = optionslog.info'verifying the user';log.infotoken 'was the token retreived';findByIdtokensubif errreturn doneerr;if !user// "Auto-registration"log.info'User was added automatically as they were new. Their sub is: ' tokensub;userspushtoken;owner = tokensub;return donenull token;owner = tokensub;return donenull user token;;;
This sample uses the OIDCStrategy:
passportusecallbackURL: configcredsreturnURLrealm: configcredsrealmclientID: configcredsclientIDclientSecret: configcredsclientSecretoidcIssuer: configcredsissueridentityMetadata: configcredsidentityMetadataskipUserProfile: configcredsskipUserProfileresponseType: configcredsresponseTyperesponseMode: configcredsresponseModeif !profileemailreturn done"No email found" null;// asynchronous verification, for effect...processnextTickfindByEmailprofileemailif errreturn doneerr;if !user// "Auto-registration"userspushprofile;return donenull profile;return donenull user;;;;
To complete the sample, provide a route that corresponds to the path configuration parameter that is sent to the strategy:
appget'/login'passportauthenticate'azuread-openidconnect' failureRedirect: '/login'log.info'Login was called in the Sample';resredirect'/';;// POST /auth/openid/return// Use passport.authenticate() as route middleware to authenticate the// request. If authentication fails, the user will be redirected back to the// login page. Otherwise, the primary route function function will be called,// which, in this example, will redirect the user to the home page.apppost'/auth/openid/return'passportauthenticate'azuread-openidconnect' failureRedirect: '/login'resredirect'/';;appget'/logout'reqlogout;resredirect'/';;
We provide a full suite of sample applications and documentation on GitHub to help you get started with learning the Azure Identity system. This includes tutorials for native clients such as Windows, Windows Phone, iOS, OSX, Android, and Linux. We also provide full walkthroughs for authentication flows such as OAuth2, OpenID Connect, Graph API, and other awesome features.
Azure Identity samples for this plug-in is here: https://github.com/AzureADSamples/WebApp-OpenIdConnect-nodejs
We leverage Stack Overflow to work with the community on supporting Azure Active Directory and its SDKs, including this one. We highly recommend you ask your questions on Stack Overflow (we're all on there!) Also browser existing issues to see if someone has had your question before.
We recommend you use the "adal" tag so we can see it! Here is the latest Q&A on Stack Overflow for ADAL: http://stackoverflow.com/questions/tagged/adal
All code is licensed under the Apache 2.0 license and we triage actively on GitHub. We enthusiastically welcome contributions and feedback. You can clone the repo and start contributing now.
More details about contribution
Please check the releases for updates.
Copyright (c) Microsoft Corp. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");