当前位置:网站首页>Using VBA's WebBrowser control to realize single sign on (SSO) in Excel
Using VBA's WebBrowser control to realize single sign on (SSO) in Excel
2022-06-10 04:03:00 【Jin Mu Zatan】
demand
Excel You can make a lot of beautiful statements on , The product manager hopes to be able to Excel Login page pops up on , Single sign on ,
After login , Retrieve the template list from the server , Select one of the templates , Insert into Excel in .
Design
- The login interface can be realized by front-end technology , such as Angular And VUE
- VBA The built-in WebBrowser Control can be loaded as Web Of the login page “ shell ”.
- VBA Keep trying to get... On the page cookie, Until you get it cookie, also cookie Contained in the token.
- Use URLDecode decode cookie, obtain token.
- Use this token issue rest api Request to get a list of templates .
Part of the implementation
from WebBrowser obtain cookie
Public Function GetCookieFromBrowser(serverIP As String)
Dim url As String
Dim encodedCookie As String
encodedCookie = ""
url = "https://" + serverIP + "/test/login/" + "?refresh=" + Guid()
FLoginWeb.FWebBrowser.Silent = True
FLoginWeb.FWebBrowser.Navigate url
FLoginWeb.Show vbModeless
Do Until InStr(FLoginWeb.FWebBrowser.Document.cookie, "token") > 0: DoEvents: Loop
If FLoginWeb.FWebBrowser.Document.cookie <> "" Then
encodedCookie = FLoginWeb.FWebBrowser.Document.cookie
FLoginWeb.Hide
End If
GetEncodedCookieFromWebBrowser = encodedCookie
End Function
Be careful
- because VBA Of WebBrowser yes IE kernel , Microsoft has officially renounced its support for IE, So with Angular、VUE Etc , There may be WebBrowser The web page cannot be loaded normally , More testing is needed .
- WebBrowser The default version used is IE7 Compatibility mode for , For a better experience , You can modify the registry to support IE11, The method is as follows :
Public Sub SetWebBrowserIE11()
Dim fso
Dim RegKey_User_IE As String
Dim oWshell
Dim excelKey As String
On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
RegKey_User_IE = "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\excel.exe"
Set oWshell = CreateObject("WScript.Shell")
excelKey = oWshell.RegRead(RegKey_User_IE)
If excelKey = "" Then
oWshell.RegWrite RegKey_User_IE, "11000", "REG_DWORD"
End If
Set oWshell = Nothing
End Sub
边栏推荐
- Distributed current limiting: current limiting based on sentinel implementation (I) - Overview
- Assembly: assembly instruction classification
- [深入研究4G/5G/6G专题-30]: 5G NR开机流程5.1 - 基站与核心网的连接(NG Setup Request、NG Setup Response)与消息详解。
- [build a neural network from scratch and improve the accuracy to 85%]
- SSTI(模板注入) ——(7)
- Data sharing between processes using queues
- Fleeing Beijing, Shanghai and Guangzhou at the age of 35, and giving away food when unemployed at the age of 40, the "dignity" of middle-aged people lies in investing in themselves
- [summary of methods to improve accuracy]
- MySQL - constraints
- Design product use
猜你喜欢

Assembly: assembly instruction classification
![[mysql] database - View](/img/5c/fc38c4a5e541810b1606e3d2a762b7.png)
[mysql] database - View

Distributed transaction solution

汇编:汇编指令分类

Why use layer 3 switches

【自适应运动补偿】基于FPGA的自适应运动补偿视频图像增强系统

Qpprogressbar+qpushbutton+qmainwindow+qtmer+ layout manager +qtextcodec+qtexttospeech in QT

工作8年月薪8000四年未涨,跳槽拿15000,原老板招不到人苦求回去

【加速 PyTorch 模型训练的 9 个技巧】

外观设计产品用途
随机推荐
[pytorch modifies the pre training model: there is little difference between the measured loading pre training model and the random initialization of the model]
[从零开始学习FPGA编程-14]:快速入门篇 - 操作步骤3(功能仿真)-3-modelsim快速使用入门(8bits循环计数器)
MySQL learning
聊聊保证线程安全的10个小技巧
"Chinese characteristics" of Web3
树的存储概念
[MySQL] 数据库-视图
MySQL - constraints
10n60-asemi medium and small power MOS transistor 10n60
[机缘参悟-21]:以系统架构的角度重新思考技术、管理、打工、创业、投资
[essence of the trilogy of sub database and sub table]
SSTI (template injection) - (6)
[pytorch model pruning example tutorial 3 (multi parameter and global pruning)]
Vulnhub's hacksudo:thor
Assembly: stack frame analysis of complete function flow
Cultural and natural heritage day, mission airdrop
[ov7670] introduction and use of ov7670 camera based on FPGA
I wrote getter and setter methods every day. I was impatient, so I used the artifact mapperstruct, and the crud efficiency was suddenly improved! (hard coding is preferred)
[summary of pytoch optimizer]
在MATLAB中使用tensorflow