2016-06-02 18 views
2

Ich habe eine grundlegende Auth-gesicherte API, aber nach dem Ausfüllen der Authentifizierungsdaten gilt es nicht für Anfrage Header. Ich sah "ERROR Server nicht gefunden oder ein Fehler ist aufgetreten" bei swagger Editor und "401 Unauthorized" auf Fiddler.Basic Auth-Header nicht gesendet (Swagger)

Benutzername und Pwd: OData und qtkr47PTM3pmzLyEHNrW4DXhhgyjMfM3CKUZfXdn0tk =

Hier ist meine Prahlerei json

{ 
"swagger": "2.0", 
"info": { 
    "version": "1.0.0", 
    "title": "Basic Auth Example", 
    "description": "An example for how to use Basic Auth with Swagger.\nServer code is available [here](http://navm3.cloudapp.net:90/nav/odata). It's running on NAVM3.\n\n**You can use below User Name and Password for test.**\n* User Name: `ODATA`\n* Password: `qtkr47PTM3pmzLyEHNrW4DXhhgyjMfM3CKUZfXdn0tk=`\n" 
}, 
"host": "navm3.cloudapp.net:90", 
"basePath": "/nav/odata", 
"schemes": [ 
    "http" 
], 
"securityDefinitions": { 
    "basicAuth": { 
     "type": "basic", 
     "description": "HTTP Basic Authentication. Works over `HTTP` and `HTTPS`" 
    } 
}, 
"paths": { 
    "/": { 
     "get": { 
      "security": [ 
       { 
        "basicAuth": [] 
       } 
      ], 
      "responses": { 
       "200": { 
        "description": "Will send `Authenticated` if authentication is succesful, otherwise it will send `Unauthorized`" 
       } 
      } 
     } 
    } 
} 

}

enter image description here

enter image description here

Antwort

1

i das hatte Das gleiche Problem, aber das Problem war im Back-End-Knoten.

Wenn Sie NodeJS verwenden, ist wahrscheinlich das Problem mit CORS. Sie sollten CORS in NodeJS mit Express aktivieren und alles wird funktionieren.

Um die CORS in nodeJS zu aktivieren, können Sie den folgenden Code vor den Routen hinzufügen.

var app = express(); 

app.use(function(req, res, next) { 

    res.setHeader('Access-Control-Allow-Origin', '*'); 

    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, UPDATE, DELETE, OPTIONS'); 

    res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization'); 

    next(); 

}); 
Verwandte Themen