guard¶
This submodule contains various functionality related to Steam Guard.
SteamAuthenticator
provides methods for genereating codes
and enabling 2FA on a Steam account. Operations managing the authenticator
on an account require an instance of either MobileWebAuth
or
SteamClient
. The instance needs to be logged in.
Adding an authenticator
sa = SteamAuthenticator(medium=medium)
sa.add() # SMS code will be send to account's phone number
sa.secrets # dict with authenticator secrets, make sure you save them
sa.finalize('SMS CODE') # activate the authenticator
sa.get_code() # generate 2FA code for login
sa.remove() # removes the authenticator from the account
Warning
Before you finalize the authenticator, make sure to save your secrets. Otherwise you will lose access to the account.
Once authenticator is enabled all you need is the secrets to generate codes.
sa = SteamAuthenticator(secrets)
sa.get_code()
You can obtain the authenticator secrets from an Android device using
extract_secrets_from_android_rooted()
. See the function docstring for
details on what is required for it to work.
-
class
steam.guard.
SteamAuthenticator
(secrets=None, medium=None)¶ Add/Remove authenticator from an account. Generate 2FA and confirmation codes.
Parameters: - secret (dict) – a dict of authenticator secrets
- medium – logged on session for steam user
-
steam_time_offset
= None¶ offset from steam server time
-
align_time_every
= 0¶ how often to align time with Steam (
0
never, otherwise interval in seconds)
-
medium
= None¶ instance of
MobileWebAuth
orSteamClient
-
get_code
(timestamp=None)¶ Parameters: timestamp (int) – time to use for code generation Returns: two factor code Return type: str
-
get_confirmation_key
(tag='', timestamp=None)¶ Parameters: - tag (str) – see
generate_confirmation_key()
for this value - timestamp (int) – time to use for code generation
Returns: trade confirmation key
Return type: - tag (str) – see
-
add
()¶ Add authenticator to an account. The account’s phone number will receive a SMS code required for
finalize()
.Raises: SteamAuthenticatorError
-
finalize
(activation_code)¶ Finalize authenticator with received SMS code
Parameters: activation_code (str) – SMS code Raises: SteamAuthenticatorError
-
remove
()¶ Remove authenticator
Note
After removing authenticator Steam Guard will be set to email codes
Warning
Doesn’t work via
SteamClient
. Disabled by ValveRaises: SteamAuthenticatorError
-
status
(medium=None)¶ Fetch authenticator status for the account
Raises: SteamAuthenticatorError
Returns: dict with status parameters Return type: dict
-
create_emergency_codes
(code=None)¶ Generate emergency codes
Parameters: code (str) – SMS code Raises: SteamAuthenticatorError
Returns: list of codes Return type: list Note
A confirmation code is required to generate emergency codes and this method needs to be called twice as shown below.
sa.create_emergency_codes() # request a SMS code sa.create_emergency_codes(code='12345') # creates emergency codes
-
destroy_emergency_codes
()¶ Destroy all emergency codes
Raises: SteamAuthenticatorError
-
add_phone_number
(phone_number)¶ Add phone number to account
Then confirm it via
confirm_phone_number()
Parameters: phone_number ( str
) – phone number with country codeReturns: success (returns False
on request fail/timeout)Return type: bool
-
confirm_phone_number
(sms_code)¶ Confirm phone number with the recieved SMS code
Parameters: sms_code ( str
) – sms codeReturns: success (returns False
on request fail/timeout)Return type: bool
-
steam.guard.
generate_twofactor_code
(shared_secret)¶ Generate Steam 2FA code for login with current time
Parameters: shared_secret (bytes) – authenticator shared shared_secret Returns: steam two factor code Return type: str
-
steam.guard.
generate_twofactor_code_for_time
(shared_secret, timestamp)¶ Generate Steam 2FA code for timestamp
Parameters: Returns: steam two factor code
Return type:
-
steam.guard.
generate_confirmation_key
(identity_secret, tag, timestamp)¶ Generate confirmation key for trades. Can only be used once.
Parameters: Returns: confirmation key
Return type: Tag choices:
conf
to load the confirmations pagedetails
to load details about a tradeallow
to confirm a tradecancel
to cancel a trade
-
steam.guard.
get_time_offset
()¶ Get time offset from steam server time via WebAPI
Returns: time offset ( None
when Steam WebAPI fails to respond)Return type: int
,None
-
steam.guard.
generate_device_id
(steamid)¶ Generate Android device id
Parameters: steamid ( SteamID
,int
) – Steam IDReturns: android device id Return type: str
-
steam.guard.
extract_secrets_from_android_rooted
(adb_path='adb')¶ Extract Steam Authenticator secrets from a rooted Android device
Prerequisite for this to work:
- rooted android device
- adb binary
- device in debug mode, connected and paired
Note
If you know how to make this work, without requiring the device to be rooted, please open a issue on github. Thanks
Parameters: adb_path (str) – path to adb binary Raises: When there is any problem Returns: all secrets from the device, steamid as key Return type: dict