Skip to content
This repository was archived by the owner on Apr 6, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
1012139
feat(mail): adds method to move newsletter settings from one to anoth…
pozylon Jan 23, 2018
31a3660
Revert "fix(auth): remove changeEmail, belongs to republik-backend"
pozylon Jan 23, 2018
a63bfa7
fix(auth): use the new moveNewsletterSubscriptions from mail
pozylon Jan 23, 2018
8226d14
fix(auth): fix clearSession
pozylon Jan 23, 2018
df5277a
fix(auth): fix updateUserEmail
pozylon Jan 23, 2018
4b4a23b
style(auth): cleanup
pozylon Jan 23, 2018
3f5a866
feat(auth): 2fa
pozylon Jan 23, 2018
1ea42c8
fix(auth): typo
pozylon Jan 23, 2018
303d0e0
feat(auth): add tokens to db
pozylon Jan 25, 2018
8aa0fe1
fix(auth): 2fa (wip)
pozylon Jan 25, 2018
8edf028
fix(auth): 2fa (wip)
pozylon Jan 30, 2018
17c7ac4
Merge branch 'master' into totp
pozylon Jan 30, 2018
22d45dd
fix(auth): 2fa
pozylon Jan 30, 2018
aefee2b
Merge branch 'fix-session-clear' into totp
pozylon Jan 30, 2018
4aff619
Merge branch 'move-interests' into totp
pozylon Jan 30, 2018
1fd936b
fix(auth): updateEmail
pozylon Jan 30, 2018
30a68d0
feat(auth): add totp setup functions
pozylon Jan 31, 2018
24a241e
fix(auth): totp setup validation
pozylon Jan 31, 2018
2bbeac8
feat(auth): enable/disable 2fa
pozylon Feb 5, 2018
7232c21
fix(auth): don’t delete tokens if initiateSession is called
pozylon Feb 5, 2018
60efe27
feat(auth): added denySession mutation
pozylon Feb 5, 2018
9b823d5
Merge remote-tracking branch 'origin/master' into totp
pozylon Feb 5, 2018
a249ada
feat(translate): Translated Error
pozylon Feb 5, 2018
233b01c
fix(base): refactored error reporting
pozylon Feb 5, 2018
b1f11f0
refactor(auth): new error codes
pozylon Feb 5, 2018
db0a032
fix(auth): 2fa mapped translated errors
pozylon Feb 6, 2018
f4f42c8
remove everything expect packages for monorepo
patte Feb 5, 2018
cd6063c
Merge branch 'totp' of /Users/patte/republik/src/republik-backends-al…
patte Feb 6, 2018
da6270c
Merge branch 'heroku' into totp
patte Feb 6, 2018
1628b86
fix(auth): reintroduce updateEmail in auth package
pozylon Feb 6, 2018
b8592ed
Merge branch 'totp' of github.com:orbiting/backends into totp
pozylon Feb 6, 2018
6627142
refactor(auth): fix tests
pozylon Feb 6, 2018
89950dd
Merge remote-tracking branch 'origin/master' into totp
pozylon Feb 14, 2018
dc45cb6
feat(sms): introduced twilio interface
pozylon Feb 14, 2018
1705e0f
feat(auth): E.164 phone number parsing & SMSCodeChallenge
pozylon Feb 14, 2018
4bb47cb
feat(auth): simplified variant of 2-factor enabled through sms
pozylon Feb 14, 2018
d0339e7
feat(auth): basic implementation of sms finalized
pozylon Feb 14, 2018
6b69c4c
Merge remote-tracking branch 'origin/master' into totp
pozylon Feb 26, 2018
6690983
feat(auth): sms
pozylon Feb 26, 2018
83ea5e0
Merge remote-tracking branch 'origin/master' into totp
pozylon Mar 8, 2018
a0864b2
feat(auth): startChallenge for 2FA
pozylon Mar 9, 2018
6b4cb6b
Merge branch 'master' into totp
pozylon Apr 3, 2018
7047aef
refactor(auth): fixed inconsistencies in the api and removed unneeded…
pozylon Apr 3, 2018
ed0de35
chore(auth): add some information on how the 2fa process works
pozylon Apr 4, 2018
2983c01
refactor(auth): wip schema changes
pozylon Apr 12, 2018
f597f4a
Merge branch 'master' into totp
pozylon Apr 12, 2018
9d2e247
build: yarn.lock fuckup
pozylon Apr 12, 2018
38aa88d
refactor(auth): remove log of payloads and change schema
pozylon Apr 16, 2018
56cfd3c
fix(auth): schema
pozylon Apr 16, 2018
d4644cc
fix(auth): schema: consistent „enabledSecondFactors“
pozylon Apr 17, 2018
e4e0a15
refactor(auth): API Change: resendPhoneNumberVeri... -> sendPhoneNumb…
pozylon Apr 18, 2018
0dd7cf8
feat(auth): independent activation of second factors
pozylon Apr 18, 2018
93893e4
fix(auth): 2fa schema implications
pozylon Apr 18, 2018
9300836
fix(auth): 2fa schema implications & clean up
pozylon Apr 18, 2018
606539e
fix(auth): mitigate crash
pozylon Apr 18, 2018
ecac493
fix(auth): race condition mitigated
pozylon Apr 18, 2018
b8a2f36
fix(auth): 2fa missing translation keys
pozylon Apr 18, 2018
8edafeb
fix(auth): 2fa transaction atomicity issue + non-optional emailFromQuery
pozylon Apr 18, 2018
80a2034
refactor(auth): increases expressiveness of ChallengeHandlerProxy
pozylon Apr 27, 2018
c5980ff
Merge branch 'totp' of github.com:orbiting/backends into totp
pozylon Apr 27, 2018
5de7f8a
fix(auth): atomically check updates to email and phonenumber
pozylon May 1, 2018
b4a8e65
fix(auth): cleanup token types for 2fa
pozylon May 1, 2018
78f0555
Merge remote-tracking branch 'origin/master' into totp
pozylon May 2, 2018
67493ba
fix(republik): make tests work again and fix authorizeSession
pozylon May 2, 2018
3e59a48
feat(auth): tests
pozylon May 2, 2018
12c03c0
feat(auth): tests revert package.json
pozylon May 2, 2018
679c051
feat(auth): tests
pozylon May 2, 2018
a24af54
feat(auth): tests
pozylon May 2, 2018
f594549
feat(auth): tests
pozylon May 10, 2018
f5728bc
feat(auth): tests
pozylon May 10, 2018
94594b6
feat(auth): tests
pozylon May 10, 2018
51f389a
fix(auth): fix various edge cases with transformUser inconsistency
pozylon May 10, 2018
65a57a4
fix(auth): updateTwoFactorAuthentication now can actually disable 2FA
pozylon May 10, 2018
38716b5
fix(auth): fix failing tests and regression
pozylon May 10, 2018
714fa1c
fix(auth): tests
pozylon May 10, 2018
bee43f5
Merge remote-tracking branch 'origin/master' into totp
pozylon May 10, 2018
dac3950
feat(consent): require consent to ENFORCE_POLICIES before a user gets…
patte May 16, 2018
ae1a59c
feat(consent): save consent, cleanup naming, translations
patte May 17, 2018
e7c0852
fix(consent): remove TOS from env example
patte May 17, 2018
c422ced
feat(consent): updateNewsletterSubscriptions with hmac'ed email upser…
patte May 17, 2018
1d2cb94
fix(newsletters): remove unused status from updateNewsletterSubscription
patte May 17, 2018
2c734da
fix(newsletters): don't auto-interest PROJECTR, don't loose newslette…
patte May 17, 2018
3f1921e
fix(consent): normalize graphql schema
patte May 17, 2018
195af06
feat(auth): newUser on UnauthorizedSession
patte May 17, 2018
82b0315
fix(travis): temp. add gdpr branch to travis (somehow doesn't build, …
patte May 17, 2018
671d748
feat(newsletters): updateMailchimp script updates mailchimp subscribe…
patte May 18, 2018
407f9b1
feat(consent): add subscribe url in updateMailchimp script
patte May 18, 2018
8867073
fix(auth): Encode email in email token challenge in base64 and url-safe
patrickvenetz May 18, 2018
8ae3d43
fix(consent): make ip column optional in db
patte May 18, 2018
d6aabd9
feat(consent): add consents to submitPledge, honour in reclaimPledge
patte May 18, 2018
4864f8e
Merge branch 'gdpr' of github.com:orbiting/backends into gdpr
patte May 18, 2018
8772b96
test(auth): Fix passed payload to a series of 2FA tests
patrickvenetz May 18, 2018
8687446
fix(reclaimPledge): better error message if pledgeUser is verified
patte May 18, 2018
8bec57b
Merge branch 'gdpr' of github.com:orbiting/backends into gdpr
patte May 18, 2018
4ae5946
feat(auth): expose phrase on Session
patte May 18, 2018
5251bee
feat(auth): supply consents on signIn mutation
patte May 18, 2018
9c41fa4
fix(newsletters): remove obsolete fixMailchimp script
patte May 18, 2018
471ab9c
test(auth): Add initial series of 2fa authorizeSession tests
patrickvenetz May 18, 2018
256eb98
fix(submitPledge): use transaction for consents actions
patte May 18, 2018
f5f0a34
Merge branch 'gdpr' of github.com:orbiting/backends into gdpr
patte May 18, 2018
aa175c1
feat(republik): add script reconstructConsents
patte May 18, 2018
57665ff
test(auth): Test checks if first sign in attempt can be claimed
patrickvenetz May 18, 2018
a9350f6
test(auth): Test checks if 2 factors need to be present to authorize
patrickvenetz May 18, 2018
7a02ded
fix(auth): better translations
patte May 18, 2018
8d487ad
test(auth): Rename to clearify
patrickvenetz May 18, 2018
e102532
test(auth): Test if multiple 2fa challenge starts still succeed
patrickvenetz May 18, 2018
5c57d91
fix(consents): honour frontend hmac format
patte May 18, 2018
9c604b3
Merge branch 'gdpr' of github.com:orbiting/backends into gdpr
patte May 18, 2018
aa00e9c
test(auth): Update to __tests__/auth to restore previous sigature
patrickvenetz May 18, 2018
bbd127a
fix(consents): limit consents on updateNewsletterSubscription
patte May 18, 2018
59da23a
Merge branch 'gdpr' of github.com:orbiting/backends into gdpr
patte May 18, 2018
b5294c3
test(auth): Sign out to prevent session spilling into other tests
patrickvenetz May 18, 2018
64b0d63
feat(consent): GRANT and REVOKE consents in an immutable fashion
patte May 18, 2018
88f8db9
Merge branch 'gdpr' of github.com:orbiting/backends into gdpr
patte May 18, 2018
b2ed978
fix(republik): remove unnecessary base64u.decode from updateNewslette…
patte May 18, 2018
cb12d0a
fix(consent): normalize pledge detection, only set SUB_URL if not use…
patte May 19, 2018
e8f5a58
fix(newsletters): missing await
patte May 19, 2018
fc0de81
fix(auth): newUser no user or user but not verified
patte May 19, 2018
da22c9e
fix(republik): enforceSubscriptions on reclaimPledge
patte May 19, 2018
1af4fdd
Merge pull request #43 from orbiting/gdpr
patte May 19, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ AUTH_MAIL_TEMPLATE_NAME=cf_signin
# optional:
#BASIC_AUTH_REALM=

# enforce user to consent to policies when trying to authorize a session
# comma separated list of values
#ENFORCE_CONSENTS=PRIVACY

#############
# mail
#############
Expand All @@ -88,7 +92,7 @@ DEFAULT_MAIL_FROM_NAME="Republik"

ASSETS_SERVER_BASE_URL=http://localhost:5020

# shared secret which which publikator-backend authenticates urls to assets-backend
# shared secret with which publikator-backend authenticates urls to assets-backend
# min 32bit
ASSETS_HMAC_KEY=RANDOM

Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ services:
branches:
only:
- master
- gdpr
matrix:
include:
- env:
Expand Down
50 changes: 50 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: "3.4"
services:
republik-backend:
build:
context: ./servers/republik
image: republik-backend:latest
links:
- redis
- postgres
environment:
- DATABASE_URL=postgres://postgres@postgres:5432/republik
- REDIS_URL=redis:6379
- PUBLIC_URL=http://localhost:8080
- PUBLIC_WS_URL_BASE=ws://localhost:8080
- FRONTEND_BASE_URL
- PUBLIC_WS_URL_PATH
- SESSION_SECRET
- CORS_WHITELIST_URL
- SEND_MAILS
- MANDRILL_API_KEY
- DEFAULT_MAIL_FROM_NAME
- DEFAULT_MAIL_FROM_ADDRESS
- AUTH_MAIL_FROM_ADDRESS
- DISPLAY_AUTHOR_SECRET
- EXO_KEY
- EXO_SECRET
- S3BUCKET
- ASSETS_BASE_URL
- KEYCDN_API_KEY
- KEYCDN_ZONE_ID
- KEYCDN_ZONE_URL
- PHANTOMJSCLOUD_API_KEY
ports:
- 8080:3020

redis:
image: redis:4-alpine
ports:
- 6379:6379

postgres:
image: postgres:10-alpine
volumes:
- postgres-data:/var/lib/postgresql
ports:
- 5432:5432


volumes:
postgres-data:
32 changes: 31 additions & 1 deletion packages/auth/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
# @orbiting/backend-modules-auth

Passwordless email authentication and basic user type for graphql. Sessions based on cookies by [express-session](https://github.com/expressjs/session). Simple [Role](lib/Roles.js) system.
GraphQL and [express-session](https://github.com/expressjs/session) based authentication module with basic user type and Simple [Role](lib/Roles.js) system. Currently supports the following authentication strategies:

- Passwordless email authentication
- SMS Code challenge
- TOTP Code challenge

Supports 2FA and allows SMS & TOTP to be used as second factor authentication providers.

Checkout the [schema](graphql/schema.js) and [schema-types](graphql/schema-types.js).

used by:
- [publikator-backend](https://github.com/orbiting/publikator-backend)
- [republik-backend](https://github.com/orbiting/republik-backend)

## 2-Factor-Auhentication Flow

Before 2FA can be enabled on a user, at least one of the SMS or TOTP providers need to get setup.

SMS:
1. updateMe (not part of the auth package) to store the user's phone number in the database, the phone number will get tagged as unverified and a code to verify the phone number is sent as short message to the new phone number.
2. sendPhoneNumberVerificationCode to have Twilio send a code to the number stored on the user.
3. verifyPhoneNumber to verify the phone number through the code that got sent by short message, will tag the user's phone number as verified

TOTP:
1. initTOTPSharedSecret will generate a new random shared secret, store it in the database and return it via mutation response
2. validateTOTPSharedSecret will succeed if the client was able to generate the correct TOTP for the current time and shared secret and tag the shared secret as verified.

Activate 2FA:
- updateTwoFactorAuthentication enabled=true will activate 2FA for a specific type of challenge if prerequisits are met, the call will fail if there is no verified TOTP shared secret and no verified phone number stored in the database at that point.

Login with 2FA:
- signIn starts the login process with the email authentication provider in place which in turn sends a token via e-mail to the user.
- unauthorizedSession will get called with the e-mail address and the token sent through e-mail to retrieve information about the session. This Session object can have multiple tokenTypes as result. If that's the case, the user can only authorize the session with a second factor.
- startChallenge starts backend processes needed to login with a certain tokenType, for SMS, the short message with the code needed to authorize the second factor will be sent only after calling this mutation.
- authorizeSession authenticates the session if first and second factor payloads are validated by the auth system. The session will now get linked to the user, the user is now finally logged in.

As soon as 2FA is enabled, updatePhoneNumber and updateEmail calls will fail until 2FA is disabled again, so users cannot lock out themselves from logging in.

## ENV
```
# where to send auth mails from
Expand Down
19 changes: 11 additions & 8 deletions packages/auth/graphql/resolvers/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,39 @@ const { flag, code } = require('country-emoji')
const useragent = require('useragent')

module.exports = {
id (session, args) {
id (session) {
return session.id
},
ipAddress (session, args) {
ipAddress (session) {
return session.sess.ip
},
userAgent (session, args) {
userAgent (session) {
return session.sess.ua &&
useragent.parse(session.sess.ua).toString()
},
email (session, args) {
email (session) {
return session.sess.email
},
country (session, args) {
country (session) {
const { geo = {} } = session.sess
return geo.country
},
countryFlag (session, args) {
countryFlag (session) {
const { geo = {} } = session.sess
const countryCode = geo.countryEN ? code(geo.countryEN) : null
return countryCode ? flag(countryCode) : '🏴'
},
city (session, args) {
city (session) {
const { geo = {} } = session.sess
return geo.city
},
expiresAt (session, args) {
expiresAt (session) {
return session.expire
},
isCurrent (session, args, { req }) {
return session.sid === req.sessionID
},
phrase (session) {
return session.sess.phrase
}
}
22 changes: 22 additions & 0 deletions packages/auth/graphql/resolvers/SharedSecretResponse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const ISSUER = 'Republik'

// https://github.com/google/google-authenticator/wiki/Key-Uri-Format
const buildOTPUrl = (email, code) =>
`otpauth://totp/${ISSUER}:${email}?secret=${code}&issuer=${ISSUER}`

const Response = {
otpAuthUrl ({ secret }, args, { pgdb, user }) {
return buildOTPUrl(user.email, secret)
},
svg ({ secret }, args, { pgdb, user }) {
const { errorCorrectionLevel } = args
const url = buildOTPUrl(user.email, secret)
const qr = require('qr-image')
return qr.imageSync(url, {
ec_level: errorCorrectionLevel,
type: 'svg'
})
}
}

module.exports = Response
10 changes: 9 additions & 1 deletion packages/auth/graphql/resolvers/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,17 @@ module.exports = {
Roles.ensureUserIsMeOrInRoles(user, me, userAccessRoles)
return user._raw.createdAt
},
updatedAt (user, args, { user: me }) {
updatedAt (user) {
return user._raw.updatedAt
},
enabledSecondFactors (user, args, { user: me }) {
if (
Roles.userIsMeOrInRoles(user, me, ['supporter'])
) {
return user._raw.enabledSecondFactors
}
return []
},
async eventLog (user, args, { pgdb, user: me }) {
Roles.ensureUserIsMeOrInRoles(user, me, userAccessRoles)
return pgdb.query(`
Expand Down
9 changes: 4 additions & 5 deletions packages/auth/graphql/resolvers/_mutations/addUserToRole.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const t = require('../../../lib/t')
const transformUser = require('../../../lib/transformUser')

const {
ensureUserHasRole,
userHasRole,
Expand All @@ -16,9 +18,6 @@ module.exports = async (_, args, { pgdb, req, signInHooks }) => {
throw new Error(t('api/users/404'))
}

if (userHasRole(user, role)) {
return user
} else {
return addUserToRole(userId, role, pgdb)
}
const returnedUser = userHasRole(user, role) ? user : (await addUserToRole(userId, role, pgdb))
return transformUser(returnedUser)
}
37 changes: 14 additions & 23 deletions packages/auth/graphql/resolvers/_mutations/authorizeSession.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
const { QueryEmailMismatchError, NoSessionError } = require('../../../lib/errors')
const t = require('../../../lib/t')
const { authorizeSession } = require('../../../lib/Sessions')
const { authorizeSession } = require('../../../lib/Users')

module.exports = async (_, args, { pgdb, req, signInHooks }) => {
const {
email,
token
tokens = [],
consents
} = args
try {
const user = await authorizeSession({
pgdb,
token,
emailFromQuery: email,
signInHooks
})
return !!user
} catch (e) {
if (e instanceof QueryEmailMismatchError) {
console.info("authorizeSession: session.email and query.email don't match: %O", { req: req._log(), ...e.meta })
} else if (e instanceof NoSessionError) {
console.info('authorizeSession: no session %O', { req: req._log(), ...e.meta })
} else {
const util = require('util')
console.error('authorizeSession: exception', util.inspect({ req: req._log(), emailFromQuery: email, e }, {depth: null}))
}
throw new Error(t('api/token/invalid'))
}

const user = await authorizeSession({
pgdb,
tokens,
email,
signInHooks,
consents,
req
})

return !!user
}
35 changes: 11 additions & 24 deletions packages/auth/graphql/resolvers/_mutations/clearSession.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const t = require('../../../lib/t')
const Roles = require('../../../lib/Roles')
const { DestroySessionError } = require('../../../lib/errors')
const ensureSignedIn = require('../../../lib/ensureSignedIn')
const { clearUserSession, destroySession } = require('../../../lib/Sessions')
const { resolveUser } = require('../../../lib/Users')
const userAccessRoles = ['admin', 'supporter']

module.exports = async (_, args, { pgdb, user: me, req }) => {
Expand All @@ -13,28 +12,16 @@ module.exports = async (_, args, { pgdb, user: me, req }) => {
sessionId
} = args

const user = foreignUserId
? (await pgdb.public.users.findOne({ id: foreignUserId }))
: me
const user = await resolveUser({ slug: foreignUserId, pgdb, userId: me.id })

try {
const session = pgdb.public.sessions.findOne({ sid: req.sessionID, email: user.email })
if (session.id === sessionId) {
// current session, normal logout
await destroySession(req)
return true
}
if (Roles.userIsMeOrInRoles(user, me, userAccessRoles)) {
return await clearUserSession({ pgdb, userId: user.id, sessionId })
}
return false
} catch (e) {
if (e instanceof DestroySessionError) {
console.error('clearSession: exception %O', { req: req._log(), userId: user.id, sessionId, ...e.meta })
} else {
const util = require('util')
console.error('clearSession: exception', util.inspect({ req: req._log(), userId: user.id, sessionId, e }, {depth: null}))
}
throw new Error(t('api/auth/errorDestroyingSession'))
const session = pgdb.public.sessions.findOne({ sid: req.sessionID, email: user.email })
if (session.id === sessionId) {
// current session, normal logout
await destroySession(req)
return true
}
if (Roles.userIsMeOrInRoles(user, me, userAccessRoles)) {
return clearUserSession({ pgdb, userId: user.id, sessionId })
}
return false
}
37 changes: 12 additions & 25 deletions packages/auth/graphql/resolvers/_mutations/clearSessions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const t = require('../../../lib/t')
const Roles = require('../../../lib/Roles')
const { DestroySessionError } = require('../../../lib/errors')
const ensureSignedIn = require('../../../lib/ensureSignedIn')
const { resolveUser } = require('../../../lib/Users')
const { clearAllUserSessions, destroySession } = require('../../../lib/Sessions')
const userAccessRoles = ['admin', 'supporter']

Expand All @@ -12,30 +11,18 @@ module.exports = async (_, args, { pgdb, user: me, req }) => {
userId: foreignUserId
} = args

const user = foreignUserId
? (await pgdb.public.users.findOne({ id: foreignUserId }))
: me
const user = await resolveUser({ slug: foreignUserId, pgdb, userId: me.id })

try {
let isSessionsCleared = false
if (me.id === user.id) {
// current user targeted, so we
// destroy the current session safely via express
if (await destroySession(req)) isSessionsCleared = true
}
if (Roles.userIsMeOrInRoles(user, me, userAccessRoles)) {
if (await clearAllUserSessions({ pgdb, userId: user.id })) {
isSessionsCleared = true
}
}
return isSessionsCleared
} catch (e) {
if (e instanceof DestroySessionError) {
console.error('clearSessions: exception %O', { req: req._log(), userId: user.id, ...e.meta })
} else {
const util = require('util')
console.error('clearSessions: exception', util.inspect({ req: req._log(), userId: user.id, e }, {depth: null}))
let isSessionsCleared = false
if (me.id === user.id) {
// current user targeted, so we
// destroy the current session safely via express
if (await destroySession(req)) isSessionsCleared = true
}
if (Roles.userIsMeOrInRoles(user, me, userAccessRoles)) {
if (await clearAllUserSessions({ pgdb, userId: user.id })) {
isSessionsCleared = true
}
throw new Error(t('api/auth/errorDestroyingSession'))
}
return isSessionsCleared
}
17 changes: 17 additions & 0 deletions packages/auth/graphql/resolvers/_mutations/denySession.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const {
denySession } = require('../../../lib/Users')

module.exports = async (_, args, { pgdb, req, signInHooks }) => {
const {
token,
email
} = args

const user = await denySession({
pgdb,
token,
email
})

return !!user
}
Loading