您如何实现与需要MFA的服务连接的扩展?

问题描述 投票:0回答:1

您将如何实现连接到需要MFA的外部服务(Office365)的扩展?

背景

我当前正在使用扩展名SPGo(https://github.com/chrishasz/spgo),该扩展名允许用户与Microsoft SharePoint Online进行交互。我的组织最近需要MFA,并且已禁用创建此问题(https://github.com/chrishasz/spgo/issues/32#issuecomment-380171567)中所述的应用程序密码的功能。

我正在尝试找出是否有什么可以建议给此扩展的实施者以使之有效的方法。如果Visual Studio Code今天不支持任何方法,则我想表达一个功能请求以支持这种类型的流程。

visual-studio-code office365 vscode-extensions
1个回答
0
投票

MFA确实是必经之路。浏览器应用程序很容易对其进行身份验证,但是桌面应用程序必须做一些额外的工作。好消息是,使用new APIs proposed in the VS Code 1.39 release会更容易。同时,需要通过使用env.openExternal(uri) API将最终用户发送到云认证页面来完成。身份验证服务通常需要了解您的应用程序,并且应该知道在成功进行MFA身份验证后将浏览器页面重定向到何处。重定向应该转到一些本地http://localhost:port/auth-callback,您必须使用express从VS Code扩展中暂时托管该本地。这是一些伪代码:

import express = require('express');
import http = require('http');

import { env } from 'vscode';

function getLoginAndGetToken(onSuccess: (token: string, ...) => void, onError: (message: string) => void) {

    var server: http.Server = null;

    app.post('/auth-callback', function (req:any, res:any) {
        server.close();
        try {
            // todo: check nonce req.body

            // extract the tokens from `req.body`
            onSuccess(req.body.xyzToken, ...);
            // todo: put some confirmation in `res`
            res.sendStatus(200);
        } catch (err) {
            onError(err);
            res.sendStatus(401);
        }
    });

    server = http.createServer(app);
    server.on('error', function (e) {
       onError(e.message);
    });
    server.listen(callbackPort);
    setTimeout( () => { server.close(); }, timeoutInMs );

    env.openExternal(clousAuthUrl + nonce);
}

然后您在与云服务的通信中使用令牌。

© www.soinside.com 2019 - 2024. All rights reserved.