New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-microsoft-login

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-microsoft-login - npm Package Compare versions

Comparing version

to
2.0.0

8

dist/helpers.d.ts

@@ -1,2 +0,2 @@

import { UserAgentApplication } from "msal";
import { PublicClientApplication } from "@azure/msal-browser";
export declare const getUserAgentApp: ({ clientId, tenantUrl, redirectUri, postLogoutRedirectUri, useLocalStorageCache, }: {

@@ -8,5 +8,5 @@ clientId: string;

useLocalStorageCache?: boolean | undefined;
}) => UserAgentApplication | undefined;
export declare const getScopes: (graphScopes?: string[] | undefined) => string[];
export declare const getLogger: (isDebugMode?: boolean | undefined) => (name: string, content?: any, isError?: boolean | undefined) => void;
}) => PublicClientApplication | undefined;
export declare const getScopes: (graphScopes?: string[]) => string[];
export declare const getLogger: (isDebugMode?: boolean) => (name: string, content?: any, isError?: boolean) => void;
export declare const checkToIE: () => boolean;

@@ -15,3 +15,3 @@ "use strict";

exports.checkToIE = exports.getLogger = exports.getScopes = exports.getUserAgentApp = void 0;
var msal_1 = require("msal");
var msal_browser_1 = require("@azure/msal-browser");
var CLIENT_ID_REGEX = /[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}/;

@@ -21,4 +21,4 @@ var getUserAgentApp = function (_a) {

if (clientId && CLIENT_ID_REGEX.test(clientId)) {
return new msal_1.UserAgentApplication({
auth: __assign(__assign(__assign(__assign({}, (redirectUri && { redirectUri: redirectUri })), (tenantUrl && { authority: tenantUrl })), (postLogoutRedirectUri && { postLogoutRedirectUri: postLogoutRedirectUri })), { clientId: clientId, validateAuthority: true, navigateToLoginRequestUrl: false }),
return new msal_browser_1.PublicClientApplication({
auth: __assign(__assign(__assign(__assign({}, (redirectUri && { redirectUri: redirectUri })), (tenantUrl && { authority: tenantUrl })), (postLogoutRedirectUri && { postLogoutRedirectUri: postLogoutRedirectUri })), { clientId: clientId, navigateToLoginRequestUrl: false }),
cache: __assign({}, (useLocalStorageCache

@@ -39,11 +39,13 @@ ? { cacheLocation: "localStorage" }

exports.getScopes = getScopes;
var getLogger = function (isDebugMode) { return function (name, content, isError) {
if (isDebugMode) {
var style = "background-color: " + (isError ? "#990000" : "#009900") + "; color: #ffffff; font-weight: 700; padding: 2px";
console.groupCollapsed("MSLogin debug");
console.log("%c" + name, style);
content && console.log(content.message || content);
console.groupEnd();
}
}; };
var getLogger = function (isDebugMode) {
return function (name, content, isError) {
if (isDebugMode) {
var style = "background-color: ".concat(isError ? "#990000" : "#009900", "; color: #ffffff; font-weight: 700; padding: 2px");
console.groupCollapsed("MSLogin debug");
console.log("%c".concat(name), style);
content && console.log(content.message || content);
console.groupEnd();
}
};
};
exports.getLogger = getLogger;

@@ -50,0 +52,0 @@ var checkToIE = function () {

import React from "react";
import { AuthResponse, AuthError, UserAgentApplication } from "msal";
import { AuthError, AuthenticationResult, PublicClientApplication } from "@azure/msal-browser";
import { User } from "@microsoft/microsoft-graph-types";
import { MicrosoftLoginButtonTheme } from "./MicrosoftLoginButton";
declare type MicrosoftLoginPrompt = "login" | "select_account" | "consent" | "none";
type MicrosoftLoginPrompt = "login" | "select_account" | "consent" | "none";
interface MicrosoftLoginProps {

@@ -14,3 +14,3 @@ /**

*/
authCallback: (error: AuthError | null, result?: AuthResponse | (AuthResponse & User), instance?: UserAgentApplication) => void;
authCallback: (error: AuthError | null, result?: AuthenticationResult | (AuthenticationResult & User), instance?: PublicClientApplication) => void;
/**

@@ -17,0 +17,0 @@ * Array of Graph API permission names.

@@ -15,3 +15,7 @@ "use strict";

if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -48,3 +52,3 @@ if (k2 === undefined) k2 = k;

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -79,3 +83,3 @@ if (y = 0, t) op = [op[0] & 2, t.value];

var graphScopes = _a.graphScopes, clientId = _a.clientId, tenantUrl = _a.tenantUrl, redirectUri = _a.redirectUri, postLogoutRedirectUri = _a.postLogoutRedirectUri, children = _a.children, buttonTheme = _a.buttonTheme, className = _a.className, _b = _a.withUserData, withUserData = _b === void 0 ? false : _b, authCallback = _a.authCallback, _c = _a.forceRedirectStrategy, forceRedirectStrategy = _c === void 0 ? false : _c, prompt = _a.prompt, debug = _a.debug, useLocalStorageCache = _a.useLocalStorageCache;
var msalInstance = helpers_1.getUserAgentApp({
var msalInstance = (0, helpers_1.getUserAgentApp)({
clientId: clientId,

@@ -87,4 +91,4 @@ tenantUrl: tenantUrl,

});
var scopes = helpers_1.getScopes(graphScopes);
var log = helpers_1.getLogger(debug);
var scopes = (0, helpers_1.getScopes)(graphScopes);
var log = (0, helpers_1.getLogger)(debug);
if (!msalInstance) {

@@ -94,13 +98,15 @@ log("Initialization", "clientID broken or not provided", true);

}
react_1.useEffect(function () {
msalInstance.handleRedirectCallback(function (error, authResponse) {
if (!error && authResponse) {
log("Fetch Azure AD 'token' with redirect SUCCEEDED", authResponse);
(0, react_1.useEffect)(function () {
msalInstance
.handleRedirectPromise()
.then(function (AuthenticationResult) {
if (AuthenticationResult) {
log("Fetch Azure AD 'token' with redirect SUCCEEDED", AuthenticationResult);
log("Fetch Graph API 'access_token' in silent mode STARTED");
getGraphAPITokenAndUser(true);
}
else {
log("Fetch Azure AD 'token' with redirect FAILED", error, true);
authCallback(error);
}
})
.catch(function (error) {
log("Fetch Azure AD 'token' with redirect FAILED", error, true);
authCallback(error);
});

@@ -110,11 +116,12 @@ }, []);

// return msalInstance to user login handler on reload if token is present
react_1.useEffect(function () {
(0, react_1.useEffect)(function () {
var clientToken = useLocalStorageCache
? localStorage.getItem("msal.idtoken")
: sessionStorage.getItem("msal.idtoken");
clientToken && getGraphAPITokenAndUser(forceRedirectStrategy || helpers_1.checkToIE());
clientToken &&
getGraphAPITokenAndUser(forceRedirectStrategy || (0, helpers_1.checkToIE)());
}, [msalInstance]);
var login = function () {
log("Login STARTED");
if (forceRedirectStrategy || helpers_1.checkToIE()) {
if (forceRedirectStrategy || (0, helpers_1.checkToIE)()) {
redirectLogin();

@@ -126,10 +133,10 @@ }

};
var finalStep = function (authResponseWithAccessToken) {
log("Fetch Graph API 'access_token' SUCCEEDED", authResponseWithAccessToken);
var finalStep = function (AuthenticationResultWithAccessToken) {
log("Fetch Graph API 'access_token' SUCCEEDED", AuthenticationResultWithAccessToken);
if (withUserData) {
getUserData(authResponseWithAccessToken);
getUserData(AuthenticationResultWithAccessToken);
}
else {
log("Login SUCCEEDED");
authCallback(null, authResponseWithAccessToken, msalInstance);
authCallback(null, AuthenticationResultWithAccessToken, msalInstance);
}

@@ -177,3 +184,3 @@ };

var popupLogin = function () { return __awaiter(void 0, void 0, void 0, function () {
var authResponse, err_2;
var AuthenticationResult, err_2;
return __generator(this, function (_a) {

@@ -186,6 +193,9 @@ switch (_a.label) {

_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, msalInstance.loginPopup({ scopes: scopes, prompt: prompt })];
return [4 /*yield*/, msalInstance.loginPopup({
scopes: scopes,
prompt: prompt,
})];
case 2:
authResponse = _a.sent();
log("Fetch Azure AD 'token' with popup SUCCEEDED", authResponse);
AuthenticationResult = _a.sent();
log("Fetch Azure AD 'token' with popup SUCCEEDED", AuthenticationResult);
log("Fetch Graph API 'access_token' in silent mode STARTED");

@@ -207,3 +217,3 @@ getGraphAPITokenAndUser();

};
var getUserData = function (authResponseWithAccessToken) { return __awaiter(void 0, void 0, void 0, function () {
var getUserData = function (AuthenticationResultWithAccessToken) { return __awaiter(void 0, void 0, void 0, function () {
var accessToken, options, response, userData;

@@ -213,3 +223,3 @@ return __generator(this, function (_a) {

case 0:
accessToken = authResponseWithAccessToken.accessToken;
accessToken = AuthenticationResultWithAccessToken.accessToken;
log("Fetch Graph API user data STARTED");

@@ -219,3 +229,3 @@ options = {

headers: {
Authorization: "Bearer " + accessToken,
Authorization: "Bearer ".concat(accessToken),
},

@@ -231,3 +241,3 @@ };

log("Login SUCCEEDED");
authCallback(null, __assign(__assign({}, userData), authResponseWithAccessToken), msalInstance);
authCallback(null, __assign(__assign({}, userData), AuthenticationResultWithAccessToken), msalInstance);
return [2 /*return*/];

@@ -234,0 +244,0 @@ }

import React from "react";
export declare type MicrosoftLoginButtonTheme = "dark_short" | "light_short" | "dark" | "light";
export type MicrosoftLoginButtonTheme = "dark_short" | "light_short" | "dark" | "light";
interface MicrosoftLoginButtonProps {

@@ -4,0 +4,0 @@ buttonTheme: MicrosoftLoginButtonTheme;

@@ -6,3 +6,3 @@ {

"types": "dist/index.d.ts",
"version": "1.15.0",
"version": "2.0.0",
"author": "alexandrtovmach@gmail.com",

@@ -25,3 +25,3 @@ "bugs": "https://github.com/alexandrtovmach/react-microsoft-login/issues",

"dependencies": {
"msal": "^1.3.2"
"@azure/msal-browser": "^2.33.0"
},

@@ -44,3 +44,2 @@ "devDependencies": {

"lint-staged": "^11.0.0",
"node-sass": "^6.0.0",
"prettier": "^2.0.5",

@@ -50,2 +49,3 @@ "react": "^17.0.1",

"react-scripts": "^4.0.0",
"sass": "^1.58.3",
"sass-loader": "^11.0.1",

@@ -52,0 +52,0 @@ "semantic-ui-css": "^2.4.1",

@@ -96,2 +96,2 @@ # react-microsoft-login

[MIT](https://github.com/alexandrtovmach/react-microsoft-login/blob/master/LICENSE)
[MIT](https://github.com/alexandrtovmach/react-microsoft-login/blob/main/LICENSE)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet