Skip to content

Commit

Permalink
Added webauthn scope support
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergei Tsoganov authored and Sergei Tsoganov committed Feb 19, 2024
1 parent c200fe4 commit e4bc8d1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CLIENT_ID=eis_client_dev
CLIENT_SECRET=asd123

# Scopes
SCOPE=openid idcard mid smartid
REACT_APP_SCOPE=openid idcard mid smartid

# Response type
RESPONSE_TYPE=code
Expand Down
57 changes: 33 additions & 24 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const {
REDIRECT_URL,
SESSION_SECRET,
TOKEN_PATH,
SCOPE,
REACT_APP_SCOPE,
RESPONSE_TYPE,
} = process.env;

Expand Down Expand Up @@ -98,31 +98,40 @@ const redirect_uri =
: `https://${HOST}${REDIRECT_URL}`;

// grant auth
app.use(
grant({
defaults: {
protocol: 'https',
host: HOST,
state: true,
callback: '/auth/callback',
transport: 'querystring',
const grantConfig = {
defaults: {
protocol: 'https',
host: HOST,
state: true,
callback: '/auth/callback',
transport: 'querystring',
},
openid: {
authorize_url: ISSUER_URL + AUTH_PATH,
access_url: ISSUER_URL + TOKEN_PATH,
oauth: 2,
key: CLIENT_ID,
secret: CLIENT_SECRET,
scope: REACT_APP_SCOPE,
redirect_uri,
response_type: RESPONSE_TYPE,
callback: REDIRECT_URL,
custom_params: {
ui_locales: LOCALE,
},
openid: {
authorize_url: ISSUER_URL + AUTH_PATH,
access_url: ISSUER_URL + TOKEN_PATH,
oauth: 2,
key: CLIENT_ID,
secret: CLIENT_SECRET,
scope: SCOPE,
redirect_uri,
response_type: RESPONSE_TYPE,
callback: REDIRECT_URL,
custom_params: {
ui_locales: LOCALE,
},
}
};

if (REACT_APP_SCOPE.includes('webauthn')) {
grantConfig.openid.scope = REACT_APP_SCOPE.replace(/(?:^|\s)webauthn(?:\s|$)/, ' ').trim();
grantConfig.openid.overrides = {
webauthn: {
scope: REACT_APP_SCOPE,
},
})
);
};
}

app.use(grant(grantConfig));

app.use(helmet());
// api
Expand Down
12 changes: 11 additions & 1 deletion src/pages/LoginPage/LoginPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Button, Container, Icon, Form } from 'semantic-ui-react';
import PropTypes from 'prop-types';
import { MainLayout, MessageModule } from '../../components';

const { REACT_APP_SERVER_PORT, REACT_APP_URL } = process.env;
const { REACT_APP_SCOPE, REACT_APP_SERVER_PORT, REACT_APP_URL } = process.env;

const authPath =
process.env.NODE_ENV === 'development'
Expand Down Expand Up @@ -48,6 +48,16 @@ function LoginPage({ user, ui }) {
<Button primary size={ui.uiElemSize} type="submit">
<FormattedMessage id="actions.login" tagName="span" />
</Button>
{REACT_APP_SCOPE && REACT_APP_SCOPE.includes('webauthn') && (
<Button
formAction={`${authPath}/webauthn`}
primary
size={ui.uiElemSize}
type="submit"
>
<FormattedMessage id="actions.webauthn-login" tagName="span" />
</Button>
)}
</Form>
</Container>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"actions.confirm.no": "No",
"actions.confirm.yes": "Yes",
"actions.login": "Sign in",
"actions.webauthn-login": "Sign in with a passkey",
"actions.save": "Save",
"app.title": "EIS Registrant portal",
"companies.addresses": "Addresses",
Expand Down
1 change: 1 addition & 0 deletions src/translations/et.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"actions.confirm.no": "Ei",
"actions.confirm.yes": "Jah",
"actions.login": "Logi sisse",
"actions.webauthn-login": "Logi sisse pääsuvõtmega",
"actions.save": "Salvesta",
"app.title": "EIS Registreerijaportaal",
"companies.addresses": "Aadressid",
Expand Down

0 comments on commit e4bc8d1

Please sign in to comment.