Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/415.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript “电子认证锁”;原始文件://不允许";_Javascript_Node.js_Electron_Auth0 - Fatal编程技术网

Javascript “电子认证锁”;原始文件://不允许";

Javascript “电子认证锁”;原始文件://不允许";,javascript,node.js,electron,auth0,Javascript,Node.js,Electron,Auth0,正在尝试使auth0与我的electron应用程序一起工作。当我遵循默认教程并尝试使用用户名密码身份验证进行身份验证时,锁失败,出现403错误,并以“Origin file://不允许”响应 我还将“文件://*”添加到auth0仪表板中客户端设置的允许来源(CORS)部分 编辑: 电子锁的设置 var lock = new Auth0Lock( 'McQ0ls5GmkJRC1slHwNQ0585MJknnK0L', 'lpsd.auth0.com', { auth:

正在尝试使auth0与我的electron应用程序一起工作。当我遵循默认教程并尝试使用用户名密码身份验证进行身份验证时,锁失败,出现403错误,并以“Origin file://不允许”响应

我还将“文件://*”添加到auth0仪表板中客户端设置的允许来源(CORS)部分

编辑:

电子锁的设置

var lock = new Auth0Lock(
   'McQ0ls5GmkJRC1slHwNQ0585MJknnK0L', 
   'lpsd.auth0.com', {
    auth: {
            redirect: false,
            sso: false
    }
});

document.getElementById('pill_login').addEventListener('click', function (e) {
    e.preventDefault();
    lock.show();
})

通过在我的electron应用程序中使用内部express服务器来处理服务页面,我能够让Auth0正常工作

首先,我在我的项目中的一个名为http的单独文件夹中创建了一个基本的express应用程序,下面是要提供的express服务器代码和html文件

const path = require('path');

const express = require('express');
const app = express();

app.use(express.static(process.env.P_DIR)); // Serve static files from the Parent Directory (Passed when child proccess is spawned).

app.use((req, res, next) => {
    res.setHeader('Access-Control-Allow-Origin', 'http://localhost:<PORT>'); // Set this header to allow redirection from localhost to auth0
    next();
})


// Default page to serve electron app
app.get('/index', (req, res) => {
    res.sendFile(__dirname + '/index.html');
})

// Callback for Auth0
app.get('/auth/callback', (req, res) => {
    res.redirect('/index'); 
})

// Listen on some port
app.listen(&lt;SOME_PORT&gt;, (err) => {
    if (err) console.log(err);
    console.log('HTTP Server running on ...');
});

现在,auth0锁按预期进行身份验证。

尝试设置本地http服务器。PHP、node和python都内置了简单的http服务器。请使用stackoverflow图像上传器上传图像,因为这样可以消除图像脱离问题的可能性。此外,请将代码粘贴到代码块中,而不是上载代码的图像,以帮助人们通过复制/粘贴(通过将每行代码缩进至少4个空格或1个选项卡来创建代码块)@Scoots我使用问题编辑器顶部的图像按钮上载图片,你能告诉我上传图片的正确位置吗?很抱歉,我一定是误读了网址。这是一种完全可以接受的包含图像的方式。@Scoots啊,在将图像包含在问题中之前,您必须拥有10个声誉。今天只创建我的帐户的缺点!你能提供一个git的例子吗?我也有同样的问题,但我不确定我是否理解这个问题solution@florin我用这个创建了一个npm模块
const {spawn} = require('child_process');

const http = spawn('node', ['./dist/http/page-server.js'], {
    env: {
        P_DIR: __dirname // Pass the current dir to the child process as an env variable, this is for serving static files in the project
    }
});

// Log standard output
http.stdout.on('data', (data) => {
    console.log(data.toString());
})

// Log errors
http.stderr.on('data', (data) => {
    console.log(data.toString());
})