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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'spaceship/lib/spaceship/upgrade_2fa_later_client.rb', line 6
def try_upgrade_2fa_later(response)
if ENV['SPACESHIP_SKIP_2FA_UPGRADE'].nil?
return false
end
puts("This account is being prompted to upgrade to 2FA")
puts("Attempting to automatically bypass the upgrade until a later date")
puts("To disable this, remove SPACESHIP_SKIP_2FA_UPGRADE=1 environment variable")
widget_key_location = response.['location']
uri = URI.parse(widget_key_location)
params = CGI.parse(uri.query)
widget_key = params.dig('widgetKey', 0)
if widget_key.nil?
STDERR.puts("Couldn't find widgetKey to continue with requests")
return false
end
response_repair = request(:get) do |req|
req.url(widget_key_location)
end
response_repair_options = request(:get) do |req|
req.url("https://appleid.apple.com/account/manage/repair/options")
req.['scnt'] = response_repair.['scnt']
req.['X-Apple-Id-Session-Id'] = response.['X-Apple-Id-Session-Id']
req.['X-Apple-Session-Token'] = response.['X-Apple-Repair-Session-Token']
req.['X-Apple-Skip-Repair-Attributes'] = '[]'
req.['X-Apple-Widget-Key'] = widget_key
req.['Content-Type'] = 'application/json'
req.['X-Requested-With'] = 'XMLHttpRequest'
req.['Accept'] = 'application/json, text/javascript'
end
request(:get) do |req|
req.url("https://appleid.apple.com/account/security/upgrade/setuplater")
req.['scnt'] = response_repair_options.['scnt']
req.['X-Apple-Id-Session-Id'] = response.['X-Apple-Id-Session-Id']
req.['X-Apple-Session-Token'] = response_repair_options.['x-apple-session-token']
req.['X-Apple-Skip-Repair-Attributes'] = '[]'
req.['X-Apple-Widget-Key'] = widget_key
req.['Content-Type'] = 'application/json'
req.['X-Requested-With'] = 'XMLHttpRequest'
req.['Accept'] = 'application/json, text/javascript'
end
response_repair_complete = request(:post) do |req|
req.url("https://idmsa.apple.com/appleauth/auth/repair/complete")
req.body = ''
req.['scnt'] = response.['scnt']
req.['X-Apple-Id-Session-Id'] = response.['X-Apple-Id-Session-Id']
req.['X-Apple-Repair-Session-Token'] = response_repair_options.['X-Apple-Session-Token']
req.['X-Apple-Widget-Key'] = widget_key
req.['Content-Type'] = 'application/json'
req.['X-Requested-With'] = 'XMLHttpRequest'
req.['Accept'] = 'application/json;charset=utf-8'
end
if response_repair_complete.status == 204
return true
else
STDERR.puts("Failed with status code of #{response_repair_complete.status}")
return false
end
rescue => error
STDERR.puts(error.backtrace)
STDERR.puts("Failed to bypass 2FA upgrade")
STDERR.puts("To disable this from trying again, set SPACESHIP_SKIP_UPGRADE_2FA_LATER=1")
return false
end
|