Microsoft Azure登录在电子应用程序中失败 [英] Microsoft Azure login fails in electron app

查看:105
本文介绍了Microsoft Azure登录在电子应用程序中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用



我尝试在file:// * Reply URL 。 azure.com rel = nofollow noreferrer> portal.azure.com -> Azure Active Directory->应用程序注册->设置(一个应用程序)->重定向URL。但是系统没有接受它。



我想要实现的是,这款Electron应用程序可以在任何系统(现在为Windows)上运行,而不会出现Azure登录问题。



您能帮助确定我可以做些什么来使这项工作吗?

解决方案

由于 Azure AD 不支持文件系统URL,因此我在Electron应用程序内部创建了本地服务器并提供了静态文件。这样,Azure的登录页面成功重定向到正确的本地主机URL(已在Azure设置的重定向URL 中添加)。



下面的代码使用 serve-static 中描述的方法。在Electron应用中创建本地服务器的代码-

  const port = 18090; //本地服务器
的端口号const appFolder =‘my_app’; //应用程序文件夹
const staticFolders =‘./my_app/路径到文件’; //静态文件的相对路径

//必需的插件
const http = require(’http’);
const finalhandler = require('finalhandler');
const serveStatic = require('serve-static');

//提供公共/ ftp文件夹
let serve = serveStatic(staticPath,{'index':['index.html','index.htm','default.html' ]});
//创建服务器
让服务器= http.createServer(function onRequest(req,res){
serve(req,res,finalhandler(req,res));
} );
server.listen(port); //在提到的端口上监听


//创建新的浏览器窗口
函数createWindow(){
let win = new BrowserWindow({
。 .. //必需的选项
});

win.loadURL(`http:// localhost:$ {port} /`); //听本地服务器
}

现在,您的Electron应用程序将监听本地服务器



注意-上述方法不适用于 asar的构建包格式文件。可能有一种可能的方法,找到后我会添加。


I am trying to integrate Microsoft Azure AD login functionality using ms-adal-angular6.

This project is on Angular-6 to create a desktop application using Electron.

Everywhere the login works fine except when I create the *.exe file because it has a file:// URL system. Below is the login failed screen after entering correct OTP during the login process.

I tried adding a file://* Reply URL under portal.azure.com -> Azure Active Directory -> App registrations -> Settings(of one app) -> Redirect URLs. But system didn't accepted it.

What I want to achieve is that this Electron app should work in any system(Windows for now) without issue of Azure login.

Can you help in determining what I could do different to make this work?

解决方案

As Azure AD doesn't support file system URL, I created a local server inside Electron app and served static files. This way the Azure's login page successfully redirects to correct localhost URL(it has been added in Redirection URLs of Azure setting).

Below code uses method described in serve-static. Code for creating the local server in Electron app -

const port = 18090; // port number for local server
const appFolder = 'my_app'; // app folder
const staticFolders = './my_app/path-to-files'; // relative path to static files

// required plugins
const http = require('http');
const finalhandler = require('finalhandler');
const serveStatic = require('serve-static');

// serve up public/ftp folder
let serve = serveStatic(staticPath, {'index': ['index.html', 'index.htm', 'default.html']});
// create server
let server = http.createServer(function onRequest(req, res) {
  serve(req, res, finalhandler(req, res));
});
server.listen(port); // listen on mentioned port


// Creating a new browser window
function createWindow() {
  let win = new BrowserWindow({
    ... // required options
  });

  win.loadURL(`http://localhost:${port}/`); // listen to local server
}

Now your Electron app will listen to a local server instead of a file system.

NOTE- Above method doesn't work for a build package with asar format file. May be there could be a possible way of doing that which I will add after finding it.

这篇关于Microsoft Azure登录在电子应用程序中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆