mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Merge branch 'master' into 106_authorization
This commit is contained in:
commit
fb885ddcda
@ -30,7 +30,7 @@
|
||||
"globalTeardown": "<rootDir>/src/jest/globalTeardown"
|
||||
},
|
||||
"dependencies": {
|
||||
"apollo-cache-inmemory": "~1.3.11",
|
||||
"apollo-cache-inmemory": "~1.3.12",
|
||||
"apollo-client": "~2.4.8",
|
||||
"apollo-link-http": "~1.5.9",
|
||||
"apollo-server": "~2.3.1",
|
||||
@ -76,7 +76,7 @@
|
||||
"eslint": "~5.11.1",
|
||||
"eslint-config-standard": "~12.0.0",
|
||||
"eslint-plugin-import": "~2.14.0",
|
||||
"eslint-plugin-jest": "^22.1.2",
|
||||
"eslint-plugin-jest": "^22.1.3",
|
||||
"eslint-plugin-node": "~8.0.0",
|
||||
"eslint-plugin-promise": "~4.0.1",
|
||||
"eslint-plugin-standard": "~4.0.0",
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { Strategy } from 'passport-jwt'
|
||||
import { fixUrl } from '../middleware/fixImageUrlsMiddleware'
|
||||
|
||||
const cookieExtractor = (req) => {
|
||||
var token = null
|
||||
@ -8,7 +9,7 @@ const cookieExtractor = (req) => {
|
||||
return token
|
||||
}
|
||||
|
||||
export default () => {
|
||||
export default (driver) => {
|
||||
const options = {
|
||||
jwtFromRequest: cookieExtractor,
|
||||
secretOrKey: process.env.JWT_SECRET,
|
||||
@ -17,16 +18,25 @@ export default () => {
|
||||
}
|
||||
|
||||
return new Strategy(options,
|
||||
(JWTPayload, next) => {
|
||||
// usually this would be a database call:
|
||||
// var user = users[_.findIndex(users, {id: JWTPayload.id})]
|
||||
// TODO: fix https://github.com/Human-Connection/Nitro-Backend/issues/41
|
||||
/* eslint-disable */
|
||||
if (true) {
|
||||
/* eslint-enable */
|
||||
next(null, {})
|
||||
async (JWTPayload, next) => {
|
||||
const session = driver.session()
|
||||
const result = await session.run(
|
||||
'MATCH (user:User {id: $userId}) ' +
|
||||
'RETURN user {.id, .slug, .name, .avatar, .email, .role} as user LIMIT 1',
|
||||
{
|
||||
userId: JWTPayload.id
|
||||
}
|
||||
)
|
||||
session.close()
|
||||
const [currentUser] = await result.records.map((record) => {
|
||||
return record.get('user')
|
||||
})
|
||||
|
||||
if (currentUser) {
|
||||
currentUser.avatar = fixUrl(currentUser.avatar)
|
||||
return next(null, currentUser)
|
||||
} else {
|
||||
next(null, false)
|
||||
return next(null, false)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ const createServer = (options) => {
|
||||
}
|
||||
const server = new GraphQLServer(Object.assign({}, defaults, options))
|
||||
|
||||
passport.use('jwt', jwtStrategy())
|
||||
passport.use('jwt', jwtStrategy(driver))
|
||||
server.express.use(passport.initialize())
|
||||
|
||||
server.express.post('/graphql', passport.authenticate(['jwt'], { session: false }))
|
||||
|
||||
28
yarn.lock
28
yarn.lock
@ -1014,16 +1014,16 @@ apollo-cache-control@^0.1.0:
|
||||
dependencies:
|
||||
graphql-extensions "^0.0.x"
|
||||
|
||||
apollo-cache-inmemory@~1.3.11:
|
||||
version "1.3.11"
|
||||
resolved "https://registry.yarnpkg.com/apollo-cache-inmemory/-/apollo-cache-inmemory-1.3.11.tgz#6cb8f24ec812715169f9acbb0b67833f9a19ec90"
|
||||
integrity sha512-fSoyjBV5RV57J3i/VHDDB74ZgXc0PFiogheNFHEhC0mL6rg5e/DjTx0Vg+csIBk23gvlzTvV+eypx7Q2NJ+dYg==
|
||||
apollo-cache-inmemory@~1.3.12:
|
||||
version "1.3.12"
|
||||
resolved "https://registry.yarnpkg.com/apollo-cache-inmemory/-/apollo-cache-inmemory-1.3.12.tgz#cf7ef7c15730d0b6787d79047d5c06087ac31991"
|
||||
integrity sha512-jxWcW64QoYQZ09UH6v3syvCCl3MWr6bsxT3wYYL6ORi8svdJUpnNrHTcv5qXqJYVg/a+NHhfEt+eGjJUG2ytXA==
|
||||
dependencies:
|
||||
apollo-cache "^1.1.21"
|
||||
apollo-utilities "^1.0.26"
|
||||
optimism "^0.6.6"
|
||||
apollo-cache "^1.1.22"
|
||||
apollo-utilities "^1.0.27"
|
||||
optimism "^0.6.8"
|
||||
|
||||
apollo-cache@1.1.22, apollo-cache@^1.1.21:
|
||||
apollo-cache@1.1.22, apollo-cache@^1.1.22:
|
||||
version "1.1.22"
|
||||
resolved "https://registry.yarnpkg.com/apollo-cache/-/apollo-cache-1.1.22.tgz#d4682ea6e8b2508a934f61c2fd9e36b4a65041d9"
|
||||
integrity sha512-8PoxhQLISj2oHwT7i/r4l+ly4y3RKZls+dtXzAewu3U77P9dNZKhYkRNAhx9iEfsrNoHgXBV8vMp64hb1uYh+g==
|
||||
@ -1307,7 +1307,7 @@ apollo-upload-server@^5.0.0:
|
||||
busboy "^0.2.14"
|
||||
object-path "^0.11.4"
|
||||
|
||||
apollo-utilities@1.0.27, apollo-utilities@^1.0.0, apollo-utilities@^1.0.1, apollo-utilities@^1.0.26, apollo-utilities@^1.0.27:
|
||||
apollo-utilities@1.0.27, apollo-utilities@^1.0.0, apollo-utilities@^1.0.1, apollo-utilities@^1.0.27:
|
||||
version "1.0.27"
|
||||
resolved "https://registry.yarnpkg.com/apollo-utilities/-/apollo-utilities-1.0.27.tgz#77c550f9086552376eca3a48e234a1466b5b057e"
|
||||
integrity sha512-nzrMQ89JMpNmYnVGJ4t8zN75gQbql27UDhlxNi+3OModp0Masx5g+fQmQJ5B4w2dpRuYOsdwFLmj3lQbwOKV1Q==
|
||||
@ -2728,10 +2728,10 @@ eslint-plugin-import@~2.14.0:
|
||||
read-pkg-up "^2.0.0"
|
||||
resolve "^1.6.0"
|
||||
|
||||
eslint-plugin-jest@^22.1.2:
|
||||
version "22.1.2"
|
||||
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-22.1.2.tgz#1ea36cc3faedbdb788e702ca633d635ca14e91e8"
|
||||
integrity sha512-jSPT4rVmNetkeCIyrvvOM0wJtgoUSbKHIUDoOGzIISsg51eWN/nISPNKVM+jXMMDI9oowbyapOnpKSXlsLiDpQ==
|
||||
eslint-plugin-jest@^22.1.3:
|
||||
version "22.1.3"
|
||||
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-22.1.3.tgz#4444108dfcddc5d2117ed6dc551f529d7e73a99e"
|
||||
integrity sha512-JTZTI6WQoNruAugNyCO8fXfTONVcDd5i6dMRFA5g3rUFn1UDDLILY1bTL6alvNXbW2U7Sc2OSpi8m08pInnq0A==
|
||||
|
||||
eslint-plugin-node@~8.0.0:
|
||||
version "8.0.0"
|
||||
@ -5719,7 +5719,7 @@ opn@4.0.2:
|
||||
object-assign "^4.0.1"
|
||||
pinkie-promise "^2.0.0"
|
||||
|
||||
optimism@^0.6.6:
|
||||
optimism@^0.6.8:
|
||||
version "0.6.8"
|
||||
resolved "https://registry.yarnpkg.com/optimism/-/optimism-0.6.8.tgz#0780b546da8cd0a72e5207e0c3706c990c8673a6"
|
||||
integrity sha512-bN5n1KCxSqwBDnmgDnzMtQTHdL+uea2HYFx1smvtE+w2AMl0Uy31g0aXnP/Nt85OINnMJPRpJyfRQLTCqn5Weg==
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user