mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
Implements dynamic retrieval of Lenovo PSREF API token
Adds a new function to programmatically retrieve the required authentication token for the Lenovo PSREF API. This change is necessary as Lenovo is now restricting API access without a JavaScript-generated token. The new function launches a headless browser instance, uses the DevTools protocol to extract the token from local storage, and then terminates the browser. This ensures continued access to the comprehensive model data available through the PSREF API, which is not fully present in other catalogs. The User-Agent string has also been updated.
This commit is contained in:
@@ -17,6 +17,20 @@ function Get-LenovoDriversModelList {
|
||||
[string]$UserAgent
|
||||
)
|
||||
|
||||
# Lenovo is special - they prevent access to the PSREF API without a cookie as of July 2025.
|
||||
# This cookie must be retrieved via Javascript
|
||||
# It appears that the cookie is hard-coded. We'll see how long this lasts.
|
||||
# If anyone knows how to reliably get the the model and machine type information from Lenovo, let me know.
|
||||
# https://download.lenovo.com/cdrt/td/catalogv2.xml only provides a subset of the information available from PSREF (e.g. it's missing 300w, 500w, and other consumer models).
|
||||
|
||||
# $lenovoCookie = "X-PSREF-USER-TOKEN=eyJ0eXAiOiJKV1QifQ.bjVTdWk0YklZeUc2WnFzL0lXU0pTeU1JcFo0aExzRXl1UGxHN3lnS1BtckI0ZVU5WEJyVGkvaFE0NmVNU2U1ZjNrK3ZqTEVIZ29nTk1TNS9DQmIwQ0pTN1Q1VytlY1RpNzZTUldXbm4wZ1g2RGJuQWg4MXRkTmxKT2YrOW9LRjBzQUZzV05HM3NpcU92WFVTM0o0blM1SDQyUlVXNThIV1VBS2R0c1B2NjJyQjIrUGxNZ2x6RTRhUjY5UDZWclBX.ZDBmM2EyMWRjZTg2N2JmYWMxZDIxY2NiYjQzMWFhNjg1YjEzZTAxNmU2M2RmN2M5ZjIyZWJhMzZkOWI1OWJhZg"
|
||||
|
||||
# Wrote a separate function to grab the token. Check the function notes for more details. Keep the above comment for now to see if the cookie ever changes.
|
||||
$lenovoCookie = Get-LenovoPSREFToken
|
||||
|
||||
# Add the cookie to the headers
|
||||
$Headers["Cookie"] = $lenovoCookie
|
||||
|
||||
WriteLog "Querying Lenovo PSREF API for model/machine type: $ModelSearchTerm"
|
||||
$url = "https://psref.lenovo.com/api/search/DefinitionFilterAndSearch/Suggest?kw=$([uri]::EscapeDataString($ModelSearchTerm))"
|
||||
$models = [System.Collections.Generic.List[PSCustomObject]]::new()
|
||||
|
||||
@@ -15,7 +15,7 @@ $script:Headers = @{
|
||||
"Accept-Encoding" = "gzip, deflate, br, zstd"
|
||||
"Accept-Language" = "en-US,en;q=0.9"
|
||||
"Priority" = "u=0, i"
|
||||
"Sec-Ch-Ua" = "`"Microsoft Edge`";v=`"125`", `"Chromium`";v=`"125`", `"Not.A/Brand`";v=`"24`""
|
||||
"Sec-Ch-Ua" = "`"Not)A;Brand`";v=`"8`", `"Chromium`";v=`"138`", `"Microsoft Edge`";v=`"138`""
|
||||
"Sec-Ch-Ua-Mobile" = "?0"
|
||||
"Sec-Ch-Ua-Platform" = "`"Windows`""
|
||||
"Sec-Fetch-Dest" = "document"
|
||||
@@ -24,7 +24,7 @@ $script:Headers = @{
|
||||
"Sec-Fetch-User" = "?1"
|
||||
"Upgrade-Insecure-Requests" = "1"
|
||||
}
|
||||
$script:UserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0'
|
||||
$script:UserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0'
|
||||
|
||||
function Get-CoreStaticVariables {
|
||||
[CmdletBinding()]
|
||||
|
||||
Reference in New Issue
Block a user