Skip to content

Commit

Permalink
Merge pull request #326 from kpi-ua/KB-167-Implement-integration-with…
Browse files Browse the repository at this point in the history
…-KPI-ID

KB-167 implement integration with KPI ID
  • Loading branch information
a-gubskiy authored Dec 10, 2024
2 parents b9089d2 + 55e4388 commit b46992f
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 313 deletions.
3 changes: 2 additions & 1 deletion public/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"ApiEndpoint": "https://api.campus.kpi.ua/",
"OldUIAddress": "https://campus.kpi.ua/",
"LoginPageAddress": "https://ecampus.kpi.ua/login"
"LoginPageAddress": "https://ecampus.kpi.ua/login",
"AppId": "3d1488ae-128e-4655-8ca2-1ef554379335"
}
13 changes: 1 addition & 12 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import SocialForbidden from './components/SocialForbidden';
import Header from './components/Header';
import Login from './components/Login';
import LecturerHelp from './components/LecturerHelp';
import KPIIDLogin from './components/KPIIDLogin';
import * as campus from './CampusClient';
import Settings from './components/Settings';
import SettingsEditor from './components/SettingsEditor';
Expand All @@ -21,7 +20,6 @@ import Feedback from './components/Feedback';
import Faq from './components/Faq';
import FindCurator from './components/FindCurator';
import AuthContainerDefault from './components/AuthContainerDefault';
import AuthContainerExternal from './components/AuthContainerExternal';
import EmploymentSystem from './components/EmploymentSystem';

const InternalLogin = () => {
Expand All @@ -32,13 +30,6 @@ const InternalLogin = () => {
);
};

const ExternalLogin = () => {
return (
<Login isExternal={true}>
<AuthContainerExternal />
</Login>
);
};

class App extends Component {
constructor(props) {
Expand All @@ -50,7 +41,7 @@ class App extends Component {
}

async componentDidMount() {
this.setState({ user: await campus.getCurrentUser() });
this.setState({ user: await campus.getCurrentUser(true) });
}

render() {
Expand All @@ -67,8 +58,6 @@ class App extends Component {
<Route exact path="/" component={InternalLogin} />
<Route exact path="/home" component={Home} />
<Route exact path="/login" component={InternalLogin} />
<Route exact path="/login/external" component={ExternalLogin} />
<Route exact path="/kpiid" component={KPIIDLogin} />
<Route exact path="/privacy" component={Privacy} />
<Route exact path="/documents" component={Documents} />
<Route exact path="/about" component={About} />
Expand Down
4 changes: 4 additions & 0 deletions src/ApplicationConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class ApplicationConfiguration {
return this.configuratiun.ApiEndpoint;
}

get KpiIdRedirectAddress() {
return `https://auth.kpi.ua?appId=${this.configuratiun.AppId}`;
}

get OldUIAddress() {
return this.configuratiun.OldUIAddress;
}
Expand Down
93 changes: 5 additions & 88 deletions src/CampusClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@ import ApplicationConfiguration from './ApplicationConfiguration';
* Application configuration
*/
export const config = {
fb: {
appId: '1214335051921931',
redirectUrl: `${ApplicationConfiguration.ApiEndpoint}account/oauth/login/fb`,
},
appDomains: [
'kpi.ua',
'campus.kpi.ua',
'ecampus.kpi.ua',
'login.kpi.ua',
'localtest.me',
'api.localtest.me',
'ecampus.localtest.me'
]
'ecampus.localtest.me',
],
};

/**
Expand Down Expand Up @@ -57,72 +53,6 @@ export const auth = async (login, password) => {
return await getCurrentUser();
};

export const externalAuth = (login, password, appId, redirectionId) => {
const payload = {
Username: login,
Password: password,
AppId: appId,
RedirectUrl: redirectionId,
};

return fetch(`https://ecampus.kpi.ua/oauth/app/authorize`, {
method: 'POST',
cache: 'no-cache',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: toUrlEncode(payload),
});
};

/**
* Request secret code for KPI ID auth
* @param phone
* @returns {Promise<Response>}
*/
export const requestKpiIdSecret = async (phone) => {
return await callApi(
'Account/oauth/login/kpiid/secret?phone=' + phone,
'GET',
);
};

/**
*
* @param phone
* @param secret
* @returns {Promise<null|*>}
*/
export const authByKpiId = async (phone, secret) => {
const payload = {
phone: phone,
secret: secret,
};
const response = await fetch(`${ApplicationConfiguration.ApiEndpoint}Account/oauth/login/kpiid`, {
method: 'POST',
cache: 'no-cache',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
});

if (response.status < 200 || response.status >= 300) {
console.warn(`Incorrect credentials`);
return null;
}

const credentials = await response.json();

if (!credentials) {
return null;
}

await storeCredentials(credentials.sessionId, credentials.access_token);

return await getCurrentUser();
};



/**
* Logout from system
* @returns {Promise<void>}
Expand Down Expand Up @@ -189,15 +119,6 @@ export const callApi = async (path, method, payload = null) => {
return await fetch(url, request);
};

/**
* Get URL for Facebook auth
* @returns {string}
*/
export const generateFacebookAuthorizationLink = () => {
const scope = 'email';
return `https://www.facebook.com/dialog/oauth?client_id=${config.fb.appId}&redirect_uri=${config.fb.redirectUrl}&scope=${scope}`;
};

/**
* Check authorization status for current user
* For authorization saved to local storage token will be used
Expand Down Expand Up @@ -382,12 +303,8 @@ const setCookie = (name, value, domain, days) => {
const expires = date.toUTCString();

document.cookie =
name +
'=' +
(value || '') +
';expires=' +
expires +
';domain=.' +
domain +
name + '=' + (value || '') +
';expires=' + expires +
';domain=.' + domain +
';path=/';
};
44 changes: 21 additions & 23 deletions src/components/AuthContainerDefault.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import React, { useState } from 'react';
import AuthForm from './AuthForm';
import * as campus from '../CampusClient';
import { useHistory } from 'react-router-dom';
import { useLocation, useHistory } from 'react-router-dom';
import ApplicationConfiguration from '../ApplicationConfiguration';

const AuthContainerDefault = () => {
const [authFail, setAuthFail] = useState(false);
const history = useHistory();
const location = useLocation();

// Parse query parameters
const queryParams = new URLSearchParams(location.search);
const showKpiIdAuthButton = queryParams.get('kid') === 'true';

const authorize = async (e, { login, password }) => {
e.preventDefault();
Expand All @@ -27,29 +33,21 @@ const AuthContainerDefault = () => {
authFail={authFail}
dismissInvalid={dismissInvalid}
>
{/*<div className="form-group">*/}
{/* <a*/}
{/* className="btn btn-block btn-social btn-facebook"*/}
{/* href={campus.generateFacebookAuthorizationLink()}*/}
{/* >*/}
{/* <div className="icon">*/}
{/* <span className="fa fa-facebook" />*/}
{/* </div>*/}
{/* Увiйти через Facebook*/}
{/* </a>*/}
{/*</div>*/}

{/*<div className="form-group">*/}
{/* <a className="btn btn-block btn-social btn-kpi-id" href="/kpiid">*/}
{/* <div className="icon">*/}
{/* <span className="fa fa-key"/>*/}
{/* </div>*/}
{/* Увiйти через KPI ID*/}
{/* </a>*/}
{/*</div>*/}

{showKpiIdAuthButton && (
<div className="form-group">
<a
className="btn btn-block btn-social btn-kpi-id"
href={ApplicationConfiguration.KpiIdRedirectAddress}
>
<div className="icon">
<span className="fa fa-key" />
</div>
Увiйти через KPI ID
</a>
</div>
)}
</AuthForm>
);
};

export default AuthContainerDefault;
export default AuthContainerDefault;
45 changes: 0 additions & 45 deletions src/components/AuthContainerExternal.js

This file was deleted.

Loading

0 comments on commit b46992f

Please sign in to comment.