Authenticator API¶
auth ¶
VK Mini App Authenticator utilities.
VKMiniAppAuthenticator ¶
VK Mini App Authenticator for validating launch parameters.
This class provides methods to extract, validate, and check the expiration of launch parameters. It uses the VK application ID and secret key to verify the signature of the parameters. The launch parameters are expected to be provided in the authorization header as a base64 encoded URL.
Source code in vk_miniapp_auth/auth.py
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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
__init__ ¶
Initializes the VK Mini App Authenticator.
Parameters:
-
app_id(int) –The VK application ID.
-
app_secret(str) –The VK application secret key.
-
ttl(timedelta, default:None) –Time to live for the launch parameters. Defaults to 1 hour.
Source code in vk_miniapp_auth/auth.py
get_launch_params ¶
Extract launch parameters from the authorization header.
This method parses and type-converts launch parameters, but does not verify the VK signature. Call is_signed() or get_verified_launch_params() before trusting the returned data.
Parameters:
-
authorization_header(str) –The authorization header containing the launch parameters.
Returns:
-
VkLaunchParams(Optional[VkLaunchParams]) –An instance of VkLaunchParams if present, otherwise None.
Source code in vk_miniapp_auth/auth.py
get_verified_launch_params ¶
Extract launch parameters and verify their VK signature.
Parameters:
-
authorization_header(str) –The authorization header containing the launch parameters.
Returns:
-
VkLaunchParams(Optional[VkLaunchParams]) –An instance of VkLaunchParams if present and valid, otherwise None.
Source code in vk_miniapp_auth/auth.py
extract_query_params_as_url staticmethod ¶
Extracts the query parameters from the authorization header.
Parameters:
-
authorization_header(str) –The authorization header containing the base64 encoded query parameters.
Returns:
-
str(str) –The decoded query parameters as a URL.
Source code in vk_miniapp_auth/auth.py
extract_query_params_as_dict staticmethod ¶
Extracts query parameters from a URL and returns them as a dictionary.
Parameters:
-
query_params_url(str) –The URL containing the query parameters.
Returns:
-
QueryParams(QueryParams) –A dictionary containing the query parameters.
Source code in vk_miniapp_auth/auth.py
is_signed ¶
Validates the signature of the launch parameters. Also checks if the parameters are not expired.
Parameters:
-
launch_params(VkLaunchParams) –The launch parameters to validate.
Returns:
-
bool(bool) –True if the launch parameters are valid and signed correctly, False otherwise.
Source code in vk_miniapp_auth/auth.py
is_expired ¶
Checks if the launch parameters are expired based on the TTL.
Parameters:
-
launch_params(VkLaunchParams) –The launch parameters to check.
Returns:
-
bool(bool) –True if the launch parameters are expired, False otherwise.