简体   繁体   English

401-未经授权的访问:Auth0和azure

[英]401 - unauthorized access : Auth0 and azure

I have connected my Database to auth0 and when I try the connection is returns 401 unauthorized access. 我已将我的数据库连接到auth0,当我尝试连接时返回401未经授权的访问。 I have allowed auth into my firewall and the password is correct. 我已将身份验证放入防火墙,并且密码正确。 How come it is returning this error when searching for username and password? 搜索用户名和密码时,为什么返回此错误?

More info 更多信息

in my easy tables I made them authenticated access only, do I have to do something to get around this? 在我的简易表中,我仅使它们成为经过身份验证的访问,是否需要做一些事情来解决此问题?

function login(email, password, callback) {
      //this example uses the "tedious" library
      //more info here: http://pekim.github.io/tedious/index.html
      var Connection = require('tedious@1.11.0').Connection;
      var Request = require('tedious@1.11.0').Request;
      var TYPES = require('tedious@1.11.0').TYPES;

      var connection = new Connection({
        userName: 'username',
        password: 'pass',
        server: 'server',
        options: {
          database: 'db',
          encrypt: true,
          rowCollectionOnRequestCompletion: true
        }
      });

      var query = "SELECT Id, Email, Password " +
        "FROM user WHERE Email = @Email";

      connection.on('debug', function (text) {
        // Uncomment next line in order to enable debugging messages
        // console.log(text);
      }).on('errorMessage', function (text) {
        console.log(JSON.stringify(text, null, 2));
        return callback(text);
      }).on('infoMessage', function (text) {
        // Uncomment next line in order to enable information messages
        // console.log(JSON.stringify(text, null, 2));
      });

      connection.on('connect', function (err) {
        if (err) { return callback(err); }

        var request = new Request(query, function (err, rowCount, rows) {
          if (err) {
            callback(new Error(err));
          } else if (rowCount < 1) {
            callback(new WrongUsernameOrPasswordError(email));
          } else {
            bcrypt.compare(password, rows[0][2].value, function (err, isValid) {
              if (err) { callback(new Error(err)); }
              else if (!isValid) { callback(new WrongUsernameOrPasswordError(email)); }
              else {
                callback(null, {
                  user_id: rows[0][0].value,
                  email: rows[0][1].value
                });
              }
            });
          }
        });

        request.addParameter('Email', TYPES.VarChar, email);
        connection.execSql(request);
      });
    }

Since you are using Azure Mobile App, which included the Node.js server SDK for your app. 由于您使用的是Azure移动应用程序,其中包括适用于您应用程序的Node.js服务器SDK Then you don't need to install tedious to work with Azure SQL database. 然后,您无需安装tedious的工作即可使用Azure SQL数据库。 The SDK has already wrapped up mssql to do this. SDK已经包装了mssql以完成此操作。 So basically you can use this code sample to connect your database. 因此,基本上,您可以使用此代码示例连接数据库。

var api = {
    // an example of executing a SQL statement directly
    get: (request, response, next) => {
        var query = {
            sql: 'UPDATE TodoItem SET complete = @completed',
            parameters: [
                { name: 'completed', value: request.query.completed }
            ]
        };

        request.azureMobile.data.execute(query)
            .then(function (results) {
                response.json(results);
            });
    },
    // an example of executing a stored procedure
    post: (request, response, next) => {
        var query = {
            sql: 'EXEC completeAllStoredProcedure @completed',
            parameters: [
                { name: 'completed', value: request.query.completed }
            ]
        };

        request.azureMobile.data.execute(query)
            .then(function (results) {
                response.json(results);
            });
    }
};

module.exports = api;

For more information, please refer to this documentation . 有关更多信息,请参阅此文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM