Skip to content

Commit

Permalink
feat: auto-sso (#325)
Browse files Browse the repository at this point in the history
* implemented auto-sso feature
  • Loading branch information
phaneendraandukuri authored Oct 25, 2021
1 parent ca437ca commit f266bd9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ jobs:
- run: |
export LHCI_SITES="[\"https://malibu-perfadvanced.quintype.io/\"]"
npx @lhci/[email protected] autorun
workflows:
version: 2
build_and_test:
Expand Down
20 changes: 16 additions & 4 deletions app/isomorphic/components/layouts/header/nav-bar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { OPEN_HAMBURGER_MENU, OPEN_SEARCHBAR, MEMBER_UPDATED } from "../../../st
import { MenuItem } from "../../menu-item";
import HamburgerMenu from "../../../atoms/hamburger-menu";
import MessageWrapper from "../../../molecules/forms/message-wrapper";

import { getAutoSSOUrl } from "@quintype/bridgekeeper-js";
import { SvgIconHandler } from "../../../atoms/svg-icon-hadler";

import "./navbar.m.css";
Expand All @@ -34,6 +34,7 @@ const NavBar = () => {
: get(publisherAttributes, ["sso_login", "redirect_Url"], "");

const ssoLoginIsEnable = get(publisherAttributes, ["sso_login", "is_enable"], false);
const isAutoSSOEnabled = get(publisherAttributes, ["auto_sso", "is_enable"], false);

const toggleHandler = () => {
dispatch({
Expand All @@ -60,6 +61,7 @@ const NavBar = () => {
try {
const currentUserResp = await currentUser();
dispatch({ type: MEMBER_UPDATED, member: get(currentUserResp, ["user"], null) });
return currentUserResp;
} catch (err) {
console.log("error--------", err);
}
Expand Down Expand Up @@ -139,7 +141,15 @@ const NavBar = () => {
const imageUrl = member && member["avatar-url"];

useEffect(() => {
getCurrentUser();
const queryParams = new URLSearchParams(window.location.search);
const queryParamExists = queryParams.has("logged_in");

getCurrentUser().then(({ user }) => {
if (isAutoSSOEnabled && !user && !queryParamExists) {
const autoSsoUrl = getAutoSSOUrl(clientId, redirectUrl, window.location.href);
window.location.replace(autoSsoUrl);
}
});

switch (global.location.hash) {
case "#email-verified":
Expand All @@ -157,10 +167,12 @@ const NavBar = () => {

const userLogin = loading => {
setLoading(loading);
if (window)
if (window) {
const callbackUrl = window.location.href.replace("?logged_in=false", "");
window.location.replace(
`/api/auth/v1/oauth/authorize?client_id=${clientId}&redirect_uri=${redirectUrl}&callback_uri=${window.location.href}&response_type=code`
`/api/auth/v1/oauth/authorize?client_id=${clientId}&redirect_uri=${redirectUrl}&callback_uri=${callbackUrl}&response_type=code`
);
}
};

const messageModal = message => {
Expand Down
2 changes: 2 additions & 0 deletions config/publisher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ publisher:
redirect_Url: "<Domain>/api/auth/v1/oauth/token"
callback_Url: "Callback Url"
timezone: "Asia/Baku"
auto_sso:
is_enable: false
google_tag_manager:
id: "gtm-id"
is_enable: true
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@loadable/component": "^5.14.1",
"@loadable/server": "^5.14.2",
"@quintype/arrow": "^2.9.9",
"@quintype/bridgekeeper-js": "^2.7.0",
"@quintype/bridgekeeper-js": "^2.8.0",
"@quintype/components": "^2.31.7",
"@quintype/framework": "^6.1.1",
"@quintype/seo": "^1.38.39",
Expand Down

0 comments on commit f266bd9

Please sign in to comment.