如何通过Native Messaging API将传递用户凭证传递给chrome [英] How to pass pass user credentials to chrome via Native Messaging API

查看:163
本文介绍了如何通过Native Messaging API将传递用户凭证传递给chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个相当具体的问题,但是如果您使用的是Selenium等,它不是Active Directory的一部分,并且您被浏览器弹出窗口阻止,我有一个解决方案你会。



我会解释问题并链接到一些资源(和其他问题,其中有更多的链接),告知解决方案,然后我会发布改变我对扩展I写入的例子。






问题:



您正在通过硒或类似的东西进行自动化或测试......并且auth弹出窗口出现蓝色!但是这个弹出窗口不是JavaScript,你不需要在你测试的机器上保存任何证书。



你如何通过身份验证凭证浏览器,并防止发生弹出...但不使用密钥库,浏览器存储或 ghasp ,文件?



一旦你知道如何将这些数据传入,然后如何将这些值传入浏览器,以便进行免提认证? 解决方案

>

解决方案:



您将需要使用浏览器扩展。
我的解决方案是为铬构建的,但它对于Firefox和边缘应该几乎保持不变。



第一,您需要2个API才能用于您的浏览器: code> - Chrome & Firefox

  • runtime.nativeMessaging - Chrome a& Firefox



  • 虽然两个浏览器API都非常相似,但它们确实有一些重大差异 - 例如Chrome的实现缺少 Promises



    如果您将本机消息传递主机设置为发送格式正确的JSON字符串,只需要轮询一次。这意味着您可以对 runtime.sendNativeMessage()使用单个调用,并确信您的凭证是可以修改的。 Pun的意图。

    下一步,我们需要看看我们应该如何处理 webRequest.onAuthRequired 事件。



    由于我在Chromium工作,我需要使用承诺少的Chrome API。

      chrome.webRequest.onAuthRequired.addListener(
    callbackFunctionHere,
    {url:[targetUrls]},
    ['asyncBlocking' ] // - >这一行也很重要。非常。



    更改:



    我会调用我的函数 provideCredentials ,因为我是一个大的stealy-stealer,并使用

    示例代码从存储中获取凭据.local ...

      chrome.storage.local.get(null,gotCredentials); 

    我们不希望这样。没有。

    我们希望从一次调用中获取证书给 sendNativeMessage ,所以我们将更改那一行。

      chrome.runtime.sendNativeMessage(hostName,{text:Ready},gotCredentials); 

    这就是所需要的。认真。只要你的主人打得好,这是一个很大的秘密。我甚至不会告诉你我花了多长时间才能找到它!



    链接:



    我的问题与有用的链接:




    • Here - 用于对Active Directory进行身份验证的解决方法 Here - 也有一些功能NM主机的工作代码


    $ b $ b

    This is a pretty specific problem to have ... but if you're using Selenium, etc, from a machine which is not part of an Active Directory and you're being foiled by browser popups, I have a solution for you.

    I will explain the problem and link to some resources (and my other questions, with even more links in them) which informed the solution then I'll post the change I made to the example for the extension I "wrote."


    Problem:

    You're automating or testing via selenium or something similar ... and an auth popup comes out of the blue! But this popup isn't JavaScript and you're required not to save any credentials on the machine you're testing from.

    How do you pass through the authentication credentials to the browser and prevent that popup from occurring ... but without using keystores, browser storage or, ghasp, a file?

    Once you know how to pass that data in, how do you then get the values into the browser in such a way as to allow hands-free authentication?

    解决方案

    Solution:

    You're going to need to use a browser extension. My solution has been built for chromium but it should port almost-unchanged for Firefox and maybe edge.

    First up, you need 2 APIs to be available for your browser:

    While both browser APIs are very similar, they do have some significant differences - such as Chrome's implementation lacking Promises.

    If you setup your Native Messaging Host to send a properly-formed JSON string, you need only poll it once. This means you can use a single call to runtime.sendNativeMessage() and be assured that your credentials are paresable. Pun intended.

    Next, we need to look at how we're supposed to handle the webRequest.onAuthRequired event.

    Since I'm working in Chromium, I need to use the promise-less Chrome API.

    chrome.webRequest.onAuthRequired.addListener(
      callbackFunctionHere,
      {urls:[targetUrls]},
      ['asyncBlocking'] // --> this line is important, too. Very.
    

    The Change:

    I'll be calling my function provideCredentials because I'm a big stealy-stealer and used an example from this source. Look for the asynchronous version.

    The example code fetches the credentials from storage.local ...

    chrome.storage.local.get(null, gotCredentials);
    

    We don't want that. Nope.

    We want to get the credentials from a single call to sendNativeMessage so we'll change that one line.

    chrome.runtime.sendNativeMessage(hostName, { text: "Ready" }, gotCredentials);
    

    That's all it takes. Seriously. As long as your Host plays nice, this is the big secret. I won't even tell you how long it took me to find it!

    Links:

    My questions with helpful links:

    • Here - Workaround for Authenticating against Active Directory
    • Here - Also has some working code for a functional NM Host
    • Here - Some enlightening material on promises

    这篇关于如何通过Native Messaging API将传递用户凭证传递给chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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