Просмотр исходного кода

Merge pull request #25 from isayme/issue/apikey-strategy

fix 24, support getting api-key from header
Pouria Ezzati 7 лет назад
Родитель
Сommit
4b726b084a
4 измененных файлов с 14 добавлено и 20 удалено
  1. 1 1
      README.md
  2. 5 16
      package-lock.json
  3. 1 1
      package.json
  4. 7 2
      server/passport.js

+ 1 - 1
README.md

@@ -72,7 +72,7 @@ In order to use these APIs you need to generate an API key from settings. Do not
 
 
 All API requests and responses are in JSON format.
 All API requests and responses are in JSON format.
 
 
-Include the API key as `apikey` in the body of all below requests. Available API URLs with body parameters:
+Include the API key as `X-API-Key` in the header of all below requests. Available API URLs with body parameters:
 
 
 **Get shortened URLs list:**
 **Get shortened URLs list:**
 ```
 ```

+ 5 - 16
package-lock.json

@@ -6189,24 +6189,13 @@
         "passport-strategy": "1.0.0"
         "passport-strategy": "1.0.0"
       }
       }
     },
     },
-    "passport-localapikey": {
-      "version": "0.0.3",
-      "resolved": "https://registry.npmjs.org/passport-localapikey/-/passport-localapikey-0.0.3.tgz",
-      "integrity": "sha1-pERzXILME1J2gp3eJ9etAfqj/aA=",
+    "passport-localapikey-update": {
+      "version": "0.6.0",
+      "resolved": "https://registry.npmjs.org/passport-localapikey-update/-/passport-localapikey-update-0.6.0.tgz",
+      "integrity": "sha512-NklCLY68AdepFID+HQ9CVPqRKKYIPw+fGQBsQoP/WZ2ovVfmJ0Qx7eoBpUtpta0vyav2TPDoHSAKoHTjO+LPcw==",
       "requires": {
       "requires": {
-        "passport": "0.1.18",
+        "passport-strategy": "1.0.0",
         "pkginfo": "0.2.3"
         "pkginfo": "0.2.3"
-      },
-      "dependencies": {
-        "passport": {
-          "version": "0.1.18",
-          "resolved": "https://registry.npmjs.org/passport/-/passport-0.1.18.tgz",
-          "integrity": "sha1-yCZEedy2QUytu2Z1LRKzfgtlJaE=",
-          "requires": {
-            "pause": "0.0.1",
-            "pkginfo": "0.2.3"
-          }
-        }
       }
       }
     },
     },
     "passport-strategy": {
     "passport-strategy": {

+ 1 - 1
package.json

@@ -53,7 +53,7 @@
     "passport": "^0.4.0",
     "passport": "^0.4.0",
     "passport-jwt": "^3.0.1",
     "passport-jwt": "^3.0.1",
     "passport-local": "^1.0.0",
     "passport-local": "^1.0.0",
-    "passport-localapikey": "0.0.3",
+    "passport-localapikey-update": "^0.6.0",
     "prop-types": "^15.6.0",
     "prop-types": "^15.6.0",
     "raven": "^2.4.0",
     "raven": "^2.4.0",
     "react": "^16.2.0",
     "react": "^16.2.0",

+ 7 - 2
server/passport.js

@@ -2,7 +2,7 @@ const passport = require('passport');
 const JwtStrategy = require('passport-jwt').Strategy;
 const JwtStrategy = require('passport-jwt').Strategy;
 const { ExtractJwt } = require('passport-jwt');
 const { ExtractJwt } = require('passport-jwt');
 const LocalStratergy = require('passport-local').Strategy;
 const LocalStratergy = require('passport-local').Strategy;
-const LocalAPIKeyStrategy = require('passport-localapikey').Strategy;
+const LocalAPIKeyStrategy = require('passport-localapikey-update').Strategy;
 const bcrypt = require('bcryptjs');
 const bcrypt = require('bcryptjs');
 const config = require('./config');
 const config = require('./config');
 const { getUser } = require('./db/user');
 const { getUser } = require('./db/user');
@@ -46,8 +46,13 @@ passport.use(
   })
   })
 );
 );
 
 
+const localAPIKeyOptions = {
+  apiKeyField: 'apikey',
+  apiKeyHeader: 'x-api-key',
+};
+
 passport.use(
 passport.use(
-  new LocalAPIKeyStrategy(async (apikey, done) => {
+  new LocalAPIKeyStrategy(localAPIKeyOptions, async (apikey, done) => {
     try {
     try {
       const user = await getUser({ apikey });
       const user = await getUser({ apikey });
       if (!user) {
       if (!user) {