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)

secrets = None

dict with authenticator secrets

medium = None

instance of MobileWebAuth or SteamClient

get_time()
Returns:Steam aligned timestamp
Return type:int
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:
Returns:

trade confirmation key

Return type:

str

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 Valve

Raises:SteamAuthenticatorError
status(medium=None)

Fetch authenticator status for the account

Raises:SteamAuthenticatorError
Returns:dict with status parameters
Return type:dict
create_emergency_codes()

Generate emergency codes

Raises:SteamAuthenticatorError
Returns:list of codes
Return type:list
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 code
Returns: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 code
Returns:success (returns False on request fail/timeout)
Return type:bool
has_phone_number()

Check whether the account has a verified phone number

Returns:result
Return type:bool or None

Note

Retruns None if the web requests fails for any reason

validate_phone_number(phone_number)

Test whether phone number is valid for Steam

Parameters:phone_number (str) – phone number with country code
Returns:see example output below
Return type:dict
{'is_fixed': False,
 'is_valid': False,
 'is_voip': True,
 'number': '+1 123-555-1111',
 'success': True}
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:
  • shared_secret (bytes) – authenticator shared secret
  • timestamp (int) – timestamp to use, if left out uses current time
Returns:

steam two factor code

Return type:

str

steam.guard.generate_confirmation_key(identity_secret, tag, timestamp)

Generate confirmation key for trades. Can only be used once.

Parameters:
  • identity_secret (bytes) – authenticator identity secret
  • tag (str) – tag identifies what the request, see list below
  • timestamp (int) – timestamp to use for generating key
Returns:

confirmation key

Return type:

bytes

Tag choices:

  • conf to load the confirmations page
  • details to load details about a trade
  • allow to confirm a trade
  • cancel 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 ID
Returns: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