keycloak-sso-toolbox
v0.2.2
Published
Repo: [as-sso-toolbox](https://bitbucket.synchrotron.org.au/projects/ST/repos/as-sso-toolbox/browse)
Readme
AS SSO Toolbox
Repo: as-sso-toolbox
SSO Toolbox is a module of functions that facilitate the use of Single Sign-On services to our authentication server.
Dependencies
Installation
Install via local NPM registry:
# install package
npm install as-sso-toolbox --registry=https://npm.asci.synchrotron.org.auUpdating
In order to publish an updated package:
Bump version number in the
package.jsonandpackage-lock.jsonBuild & publish package: \
# build package npm run build # set package registry npm config set registry https://npm.asci.synchrotron.org.au # publish package npm publishCommit code to repo
mainbranch
(Do this step last, otherwise the pipeline will try to bump the version without publishing the updates)Update the package in relevant repos: \
npm update as-sso-toolbox --registry=https://npm.asci.synchrotron.org.au
Usage
You'll need to wrap your application in SingleSignOnProvider which will provide the right context to the other components.
The redirect URL hostname is taken from the client set at clientId, so ensure you're using the correct SSO client ID for your app.
Refer to the example below.
Example
SingleSignOnProvider
import App from "@/App.tsx";
import { SingleSignOnProvider, KeycloakConfig } from "as-sso-toolbox";
const keycloakConfig: KeycloakConfig = {
url: "Keycloak URL",
realm: "keycloak realm",
clientId: "keycloak client id",
};
export const Main = () => {
return (
<SingleSignOnProvider keycloakConfig={keycloakConfig}>
<div>App</div>
</SingleSignOnProvider>
);
};useSingleSignOn
import { useSingleSignOn } from "as-sso-toolbox";
export const Header = (props: AccountProps) => {
const { logout } = useSingleSignOn();
return <button onClick={() => logout()}>Logout</button>
}