2.0.4 • Published 5 months ago

bff-auth-lib v2.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

This npm package facilitates authentication between ReactJS client and IdentityServer via Asp.Net Core based BFF (Backend For Frontend).

This package provides an abstraction as React Context and provides a context hook to access the claims anywhere provided a component root consumes the AuthProvider context.

WARNING: This package is built for a custom app. It will NOT work in other scenarios.

  • Sample code where context is provided to the App
const bffProps: Bff = {
  sitePathName: "import.meta.env.VITE_BFF_BASE_PATH",
  bffLoginEndpoint: `/bff/login?returnUrl=${import.meta.env.VITE_RETURN_URL}`,
  bffUserEndpoint: "/bff/user",
  bffMeuEndpoint: null,
  appName:'name_of_the_app_for_403_unauthorized_message'
};

ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
  <AuthProvider bff={bffProps}>
    <App />
  </AuthProvider>
);

How it works?

  1. As we've SSO (Single sign in), assuming, the users are logged in most of the time, the library sends a fetch request to get user info (/bff/user).
  2. If user is already logged in, gets user info else redirects to the identity provider url.
  3. STS redirects to the app based on redirectUrl after successful authentication.
  4. Client sends once again request to the user endpoint and successfully receives user claims.
  5. Now, it let React to render the application.

Publish to npm

  1. Build the library npm run build
  2. Publish to npm npm publish - must have a account in the npm

Link to the npm

https://www.npmjs.com/package/bff-auth-lib

2.0.3

5 months ago

2.0.2

5 months ago

2.0.4

5 months ago

2.0.1

9 months ago

2.0.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago