Skip to content

Commit

Permalink
fixes aesirxio#64 Demo user
Browse files Browse the repository at this point in the history
  • Loading branch information
vietredweb committed May 9, 2023
1 parent 90a0dff commit aed662b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
window.aesirxClientSecret="[REPLACE THIS WITH THE PROVIDED CLIENT_SECRET]"
window.aesirxClientID="[REPLACE THIS WITH THE PROVIDED CLIENT_ID]"
window.aesirxAllowedLogins=['concordium', 'metamask', 'regular']
window.demoUser=demo-user
window.demoPassword=demo-password
</script>
<script async defer src="YOUR_PROJECT_PATH/sso.js"></script>
```
Expand Down Expand Up @@ -90,6 +92,8 @@ import { SSOButton } from 'aesirx-sso';
text={"SSO Login"}
onGetData={onGetData}
options={['concordium', 'metamask', 'regular']}
demoUser="demo-user"
demoPassword="demo-password"
/>
```

Expand Down Expand Up @@ -139,5 +143,7 @@ import { SSOButton } from 'aesirx-sso';
text={"SSO Login"}
onGetData={onGetData}
options={['concordium', 'metamask', 'regular']}
demoUser="demo-user"
demoPassword="demo-password"
/>
```
6 changes: 4 additions & 2 deletions src/SSOButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState } from 'react';
import { handleWalletResponse } from '../utils/index';
import Spinner from '../Spinner/index';

const SSOButton = ({ className, text, onGetData, options }) => {
const SSOButton = ({ className, text, onGetData, options, demoUser, demoPassword }) => {
const [loading, setLoading] = useState(false);

const handleSSO = async () => {
Expand All @@ -11,7 +11,9 @@ const SSOButton = ({ className, text, onGetData, options }) => {
process.env.REACT_APP_ENDPOINT_URL ?? process.env.NEXT_PUBLIC_ENDPOINT_URL,
process.env.REACT_APP_SSO_CLIENT_ID ?? process.env.NEXT_PUBLIC_SSO_CLIENT_ID,
onGetData,
options
options,
demoUser,
demoPassword
);
};

Expand Down
4 changes: 3 additions & 1 deletion src/sso.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const aesirxSSO = async () => {
window.aesirxEndpoint,
window.aesirxClientID,
onGetData,
window.aesirxAllowedLogins
window.aesirxAllowedLogins,
window.demoUser,
window.demoPassword
);
};
handleRegularReponse(
Expand Down
8 changes: 6 additions & 2 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ const handleWalletResponse = (
_endPoint,
clientID,
onGetData,
aesirxAllowedLogins = ['concordium', 'metamask', 'regular']
aesirxAllowedLogins = ['concordium', 'metamask', 'regular'],
demoUser,
demoPassword
) => {
const endPoint = _endPoint ? new URL(_endPoint)?.origin : '';
const optionList = aesirxAllowedLogins?.length
? aesirxAllowedLogins?.map((item) => `&login[]=${item}`).join('')
: '';
const ssoState = 'sso';
const popupLink = `${endPoint}/index.php?option=authorize&api=oauth2&response_type=code&client_id=${clientID}&state=${ssoState}${optionList}`;
const demoAccount =
demoUser && demoPassword ? '&demo_user=' + demoUser + '&demo_password=' + demoPassword : '';
const popupLink = `${endPoint}/index.php?option=authorize&api=oauth2&response_type=code&client_id=${clientID}&state=${ssoState}${optionList}${demoAccount}`;
let popup = window.open(popupLink, 'SSO', 'status=1,height=650,width=650');
var timer = setInterval(async () => {
if (popup.closed) {
Expand Down

0 comments on commit aed662b

Please sign in to comment.