Auth
check_token_authentication(*, uri, device_code)
Checks the authentication status of a token based on a device code and returns access token upon successful authentication.
Parameters
- uri (str): The token uri to send the request to.
- device_code (str): The device code to check authentication for.
Returns
- str | None: The access token if authorized, otherwise None.
Raises
- requests.HTTPError: If the status code of the response is not 200.
Example Usage:
token = check_token_authentication(
uri="https://example.com/api/", device_code="1234567890"
)
if token is not None:
print("Access token:", token)
else:
print("Authentication expired.")
Source code in dvc_studio_client/auth.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
get_access_token(*, hostname, token_name=None, scopes='', client_name='client', open_browser=True, post_login_message=None, use_device_code=False, team_names=None, all_teams=None, expires_in_days=None, never_expires=None)
Initiate Authentication
This method initiates the authentication process for a client application. It generates a user code and a verification URI that the user needs to access in order to authorize the application.
Parameters
token_name (str): The name of the client application.
hostname (str): The base URL of the application.
scopes (str, optional): A comma-separated string of scopes that
the application requires. Default is empty.
open_browser (bool): Whether or not to open the browser to authenticate
client_name (str, optional): Client name
Team Scoping Parameters
team_names (list[str], optional): List of team names to scope the token to. all_teams (bool, optional): Grant access to all teams.
Expiration Parameters
expires_in_days (int, optional): Token lifetime in days. never_expires (bool, optional): Create a token that never expires.
Returns
tuple: A tuple containing the token name and the access token.
The token name is a string representing the token's name,
while the access token is a string representing the authorized access token.
Source code in dvc_studio_client/auth.py
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 | |
start_device_login(*, client_name, base_url=None, token_name=None, scopes=None, team_names=None, all_teams=None, expires_in_days=None, never_expires=None)
This method starts the device login process for Studio.
Parameters
- client_name (required): The name of the client application.
Optional Parameters: - base_url: The base URL of the Studio API. If not provided, the default value is "https://studio.datachain.ai". - token_name: The name of the token. If not provided, it defaults to None. - scopes: A list of scopes to request. If not provided, it defaults to None.
Team Scoping Parameters: - team_names: A list of team names to scope the token to. - all_teams: Grant access to all teams.
Expiration Parameters: - expires_in_days: Token lifetime in days. - never_expires: Create a token that never expires.
Returns
- DeviceLoginResponse: A response object containing the device login information.
Raises
- ValueError: If any of the provided scopes are not valid.
- RequestException: If the request fails with any 400 response or any other reason.
Source code in dvc_studio_client/auth.py
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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |