-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_sso_websession.ps1
69 lines (61 loc) · 1.86 KB
/
build_sso_websession.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<#
.SYNOPSIS
Build a session from the cod_login.ps1 output
.DESCRIPTION
Build a session from the cod_login.ps1 output
.EXAMPLE
PS> .\build_sso_websession.ps1
Headers : {[Authorization, bearer ****], [X_COD_DEVICE_ID, ****]}
Cookies : System.Net.CookieContainer
UseDefaultCredentials : False
Credentials :
Certificates :
UserAgent : cod-ate-worker
Proxy :
MaximumRedirection : -1
MaximumRetryCount : 0
RetryIntervalInSeconds : 0
.PARAMETER loginData
Login data object, returned by cod_login.ps1 using the -ReturnLoginInformation switch
.PARAMETER SaveFile
Login save file, returned by default by cod_login.ps1 without using the -ReturnLoginInformation switch
.PARAMETER CookieDomain
The domain to match the cookies of the WebSession
#>
param(
$loginData,
[string]
$SaveFile = "login_data.json",
[string]
$CookieDomain = "profile.callofduty.com"
)
if ($null -eq $loginData) {
if ($null -ne $SaveFile) {
$loginRaw = Get-Content $SaveFile
if ($loginRaw) {
$loginData = $loginRaw | ConvertFrom-Json
if ($null -eq $loginData) {
Write-Error "Can't read '$SaveFile', bad json?"
Exit -1
}
}
else {
Write-Error "'$SaveFile' doesn't exist or can't be read."
Exit -1
}
}
else {
Write-Error "`$loginData and `$SaveFile can't both be null."
Exit -1
}
}
$loginResponse = $loginData.login_response
$authHeader = $loginData.auth_header
$deviceId = $loginData.device_id
$UserArgent = "cod-ate-worker"
$CodSession = [Microsoft.PowerShell.Commands.WebRequestSession]::new()
$CodSession.Headers.Add("Authorization", "bearer $authHeader")
$CodSession.Headers.Add("X_COD_DEVICE_ID", $deviceId)
$CodSession.Cookies.Add([System.Net.Cookie]::new("ACT_SSO_COOKIE", $loginResponse.ACT_SSO_COOKIE, "/", $CookieDomain))
$CodSession.UserAgent = $UserArgent
return $CodSession