Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sassoftware/af-axios

Package Overview
Dependencies
Maintainers
13
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sassoftware/af-axios - npm Package Compare versions

Comparing version 0.5.0 to 0.6.1

react/AfAuthProvider.d.ts

2

package.json
{
"name": "@sassoftware/af-axios",
"version": "0.5.0",
"version": "0.6.1",
"description": "Minimal Axios HTTP client wrapper with SAS authentication support",

@@ -5,0 +5,0 @@ "author": "SAS",

@@ -10,3 +10,3 @@ /*

import { useMsalAuthentication } from '@azure/msal-react';
import { AuthError, RedirectRequest, SilentRequest } from '@azure/msal-browser';
import { AuthError, RedirectRequest, SilentRequest, PublicClientApplication } from '@azure/msal-browser';

@@ -28,2 +28,25 @@ interface AuthContextProviderProps {

export { AxiosInstanceContext, Auth as MsalAuth, useAxios };
interface AfAuthProviderBaseProps {
children: ReactNode;
url: string;
clientId: string;
axiosConfig?: Omit<AxiosRequestConfig, 'baseURL'>;
authenticationRequest?: RedirectRequest | SilentRequest;
loadingState?: ReactNode;
errorState?: ReactNode;
onAuthError?: (error: AuthError) => void;
}
interface AfAuthProviderWithVariables extends AfAuthProviderBaseProps {
environment: string;
tenantId: string;
msalInstance?: never;
}
interface AfAuthProviderWithMsal extends AfAuthProviderBaseProps {
msalInstance: PublicClientApplication;
environment?: never;
tenantId?: never;
}
type AfAuthProviderProps = AfAuthProviderWithVariables | AfAuthProviderWithMsal;
declare const AfAuthProvider: ({ children, url, clientId, environment, tenantId, authenticationRequest, axiosConfig, loadingState, errorState, msalInstance, onAuthError, }: AfAuthProviderProps) => JSX.Element;
export { AfAuthProvider, AxiosInstanceContext, Auth as MsalAuth, useAxios };

@@ -15,17 +15,17 @@ /*

var __defProp = Object.defineProperty;
var __defProp$1 = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues$1 = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__hasOwnProp$1.call(b, prop))
__defNormalProp$1(a, prop, b[prop]);
if (__getOwnPropSymbols$1)
for (var prop of __getOwnPropSymbols$1(b)) {
if (__propIsEnum$1.call(b, prop))
__defNormalProp$1(a, prop, b[prop]);
}

@@ -89,3 +89,3 @@ return a;

try {
const response = yield msalInstance.acquireTokenSilent(__spreadProps(__spreadValues({}, authenticationRequest), {
const response = yield msalInstance.acquireTokenSilent(__spreadProps(__spreadValues$1({}, authenticationRequest), {
account

@@ -114,2 +114,84 @@ }));

const useMsalIntance = (clientId, environment, tenantId) => {
const msalInstance = react.useMemo(() => {
var _a;
const instance = new msalBrowser.PublicClientApplication({
auth: {
clientId,
authority: `https://${environment}/${tenantId}`
}
});
if (!instance.getActiveAccount() && instance.getAllAccounts().length > 0) {
instance.setActiveAccount(
(_a = instance.getAllAccounts().find(
(account) => account.environment === environment && account.tenantId === tenantId
)) != null ? _a : null
);
}
return instance;
}, [clientId, environment, tenantId]);
msalInstance.addEventCallback((event) => {
if (event.eventType === msalBrowser.EventType.LOGIN_SUCCESS && event.payload) {
const payload = event.payload;
const account = payload.account;
msalInstance.setActiveAccount(account);
}
});
return msalInstance;
};
var __defProp = Object.defineProperty;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
const loadingWrapperStyle = {
height: "100vh",
display: "flex",
justifyContent: "center",
alignItems: "center"
};
const AfAuthProvider = ({
children,
url,
clientId,
environment,
tenantId,
authenticationRequest = {
scopes: [`${clientId}/.default`]
},
axiosConfig,
loadingState,
errorState,
msalInstance,
onAuthError
}) => {
const instance = useMsalIntance(clientId, environment, tenantId);
return /* @__PURE__ */ jsxRuntime.jsx(msalReact.MsalProvider, { instance: msalInstance || instance, children: /* @__PURE__ */ jsxRuntime.jsx(
Auth,
{
axiosConfig: __spreadValues({ baseURL: url }, axiosConfig),
onAuthError: onAuthError || ((err) => {
console.error(err);
}),
authenticationRequest,
loadingElement: loadingState || /* @__PURE__ */ jsxRuntime.jsx("div", { style: loadingWrapperStyle, children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: "loading..." }) }),
errorElement: errorState || /* @__PURE__ */ jsxRuntime.jsx("div", { style: loadingWrapperStyle, children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: "error..." }) }),
children
}
) });
};
exports.AfAuthProvider = AfAuthProvider;
exports.AxiosInstanceContext = AxiosInstanceContext;

@@ -116,0 +198,0 @@ exports.MsalAuth = Auth;

export { default as MsalAuth } from './Auth';
export { default as useAxios } from './useAxios';
export { default as AxiosInstanceContext } from './AxiosInstanceContext';
export { default as AfAuthProvider } from './AfAuthProvider';
//# sourceMappingURL=index.d.ts.map

@@ -8,2 +8,3 @@ /*

export { default as AxiosInstanceContext } from './AxiosInstanceContext';
export { default as AfAuthProvider } from './AfAuthProvider';
//# sourceMappingURL=index.js.map

@@ -8,2 +8,4 @@ # SAS&reg; af-axios

#### MSAL Provider
```javascript

@@ -34,2 +36,62 @@ // Auth.js

#### Af Authentication Provider
##### With environemnt and tenantId variabled
```javascript
// index.js or app.js
import { AfAuthProvider } from '@sassoftware/af-axios/react';
// Or any other source for given variables
const { MSAL_CLIENT_ID, MSAL_ENVIRONMENT, MSAL_TENANT_ID, AF_URL } = import.meta.env;
export const RootApp = () => (
<ErrorBoundary>
<Router>
<AfAuthProvider
url={AF_URL}
clientId={MSAL_CLIENT_ID}
environment={MSAL_ENVIRONMENT}
tenantId={MSAL_TENANT_ID}
>
<App />
</AfAuthProvider>
</Router>
</ErrorBoundary>
);
```
##### Custom msal instance
```javascript
// index.js or app.js
import { AfAuthProvider } from '@sassoftware/af-axios/react';
// Or any other souce for given variables
const { MSAL_CLIENT_ID, AF_URL } = import.meta.env;
const msalInstance = new PublicClientApplication({
auth: {
clientId: 'your client id',
authority: `https://${your evironemnt}/${your tenant id}`,
},
});
// any other msal configurations you may need
export const RootApp = () => (
<ErrorBoundary>
<Router>
<AfAuthProvider
url={AF_URL}
clientId={MSAL_CLIENT_ID}
msalInstance={msalInstance}
>
<App />
</AfAuthProvider>
</Router>
</ErrorBoundary>
);
```
## Local development

@@ -36,0 +98,0 @@

@@ -8,1 +8,2 @@ /*

export { default as AxiosInstanceContext } from './AxiosInstanceContext';
export { default as AfAuthProvider } from './AfAuthProvider';

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc