-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SEBankID app switch support for Desktop, Android & iOS
- Loading branch information
1 parent
6b943fc
commit 96b9815
Showing
20 changed files
with
594 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/components/AuthMethodButton/AuthMethodButton.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react'; | ||
import { ComponentStory, ComponentMeta } from '@storybook/react'; | ||
|
||
import AuthMethodButton from './AuthMethodButton'; | ||
import CriiptoVerifyProvider from '../../provider'; | ||
import { acrValueToTitle } from '../../utils'; | ||
import StoryResponseRenderer from '../../stories/StoryResponseRenderer'; | ||
|
||
export default { | ||
title: 'Components/AuthMethodButton', | ||
argTypes: { | ||
completionStrategy: { | ||
name: 'Completion strategy', | ||
control: 'select', | ||
defaultValue: 'client', | ||
options: ['client', 'openidprovider'] | ||
}, | ||
response: { | ||
name: 'Response mode', | ||
control: 'select', | ||
defaultValue: 'token', | ||
options: ['token', 'code'] | ||
} | ||
} | ||
} as ComponentMeta<typeof AuthMethodButton>; | ||
|
||
// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args | ||
const Template: ComponentStory<typeof AuthMethodButton> = (args, {globals}) => { | ||
return ( | ||
<CriiptoVerifyProvider completionStrategy={(args as any).completionStrategy} response={(args as any).response} domain={globals.domain} clientID={globals.clientID} redirectUri="https://httpbin.org/get"> | ||
<StoryResponseRenderer> | ||
<AuthMethodButton {...args}> | ||
{acrValueToTitle('en', args.acrValue).title}<br /> | ||
{acrValueToTitle('en', args.acrValue).subtitle} | ||
</AuthMethodButton> | ||
</StoryResponseRenderer> | ||
</CriiptoVerifyProvider> | ||
); | ||
}; | ||
|
||
export const SEBankIDSameDeviceButton = Template.bind({}); | ||
SEBankIDSameDeviceButton.args = { | ||
acrValue: 'urn:grn:authn:se:bankid:same-device' | ||
}; | ||
SEBankIDSameDeviceButton.storyName = "se:bankid:same-device"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React, { useState } from 'react'; | ||
import usePageVisibility from '../../hooks/usePageVisibility'; | ||
import {Links} from './shared'; | ||
|
||
interface Props { | ||
children: React.ReactElement, | ||
links: Links, | ||
onError: (error: string) => void | ||
onComplete: (completeUrl: string) => Promise<void> | ||
onInitiate: () => void | ||
onLog: (...statements: string[]) => void | ||
} | ||
|
||
/* | ||
* Android: Background/Foreground scenario | ||
*/ | ||
export default function SEBankIDSameDeviceAndroid(props: Props) { | ||
const {links, onError, onComplete, onInitiate, onLog} = props; | ||
const [initiated, setInitiated] = useState(false); | ||
|
||
usePageVisibility(async () => { | ||
onLog('android', 'onForeground', initiated.toString()); | ||
if (!initiated) return; | ||
|
||
onComplete(links.completeUrl); | ||
}, [links, initiated]); | ||
|
||
const handleInitiate = () => { | ||
onLog('android', 'handleInitiate'); | ||
onInitiate(); | ||
setInitiated(true); | ||
}; | ||
|
||
return React.cloneElement(props.children, { | ||
...props.children.props, | ||
onClick: handleInitiate | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React, { useContext, useEffect, useState } from 'react'; | ||
import CriiptoVerifyContext from '../../context'; | ||
import {Links} from './shared'; | ||
|
||
interface Props { | ||
children: React.ReactElement | ||
links: Links | ||
onError: (error: string) => void | ||
onComplete: (completeUrl: string) => Promise<void> | ||
onInitiate: () => void | ||
onLog: (...statements: string[]) => void | ||
} | ||
|
||
/* | ||
* Desktop: Polling scenario | ||
*/ | ||
export default function SEBankIDSameDeviceDesktop(props: Props) { | ||
const {links, onError, onComplete, onInitiate} = props; | ||
const [initiated, setInitiated] = useState(false); | ||
const {domain} = useContext(CriiptoVerifyContext); | ||
|
||
useEffect(() => { | ||
if (!initiated) return; | ||
|
||
let timeout : string | undefined; | ||
const poll = async () => { | ||
const response = await fetch(links.pollUrl); | ||
|
||
if (response.status === 202) { | ||
setTimeout(poll, 1000); | ||
return; | ||
} else if (response.status >= 400) { | ||
const error = await response.text(); | ||
onError(error); | ||
return; | ||
} else { | ||
const {targetUrl} = await response.json(); | ||
await onComplete(`https://${domain}${targetUrl}`); | ||
return; | ||
} | ||
}; | ||
|
||
setTimeout(poll, 1000); | ||
return () => { | ||
if (timeout) clearTimeout(timeout); | ||
}; | ||
}, [initiated]); | ||
|
||
const handleInitiate = () => { | ||
onInitiate(); | ||
setInitiated(true); | ||
}; | ||
|
||
return React.cloneElement(props.children, { | ||
...props.children.props, | ||
onClick: handleInitiate | ||
}); | ||
} |
Oops, something went wrong.