Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
_auth_record.py115 linesDownload Raw Back to identity
1# ------------------------------------2# Copyright (c) Microsoft Corporation.3# Licensed under the MIT License.4# ------------------------------------5import json6 7 8SUPPORTED_VERSIONS = {"1.0"}9 10 11class AuthenticationRecord:12    """Non-secret account information for an authenticated user13 14    This class enables :class:`DeviceCodeCredential` and :class:`InteractiveBrowserCredential` to access15    previously cached authentication data. Applications shouldn't construct instances of this class. They should16    instead acquire one from a credential's **authenticate** method, such as17    :func:`InteractiveBrowserCredential.authenticate`. See the user_authentication sample for more details.18 19    :param str tenant_id: The tenant the account should authenticate in.20    :param str client_id: The client ID of the application which performed the original authentication.21    :param str authority: The authority host used to authenticate the account.22    :param str home_account_id: A unique identifier of the account.23    :param str username: The user principal or service principal name of the account.24    """25 26    def __init__(self, tenant_id: str, client_id: str, authority: str, home_account_id: str, username: str) -> None:27        self._authority = authority28        self._client_id = client_id29        self._home_account_id = home_account_id30        self._tenant_id = tenant_id31        self._username = username32 33    @property34    def authority(self) -> str:35        """The authority host used to authenticate the account.36 37        :rtype: str38        """39        return self._authority40 41    @property42    def client_id(self) -> str:43        """The client ID of the application which performed the original authentication.44 45        :rtype: str46        """47        return self._client_id48 49    @property50    def home_account_id(self) -> str:51        """A unique identifier of the account.52 53        :rtype: str54        """55        return self._home_account_id56 57    @property58    def tenant_id(self) -> str:59        """The tenant the account should authenticate in.60 61        :rtype: str62        """63        return self._tenant_id64 65    @property66    def username(self) -> str:67        """The user principal or service principal name of the account.68 69        :rtype: str70        """71        return self._username72 73    @classmethod74    def deserialize(cls, data: str) -> "AuthenticationRecord":75        """Deserialize a record.76 77        :param str data: A serialized record.78        :return: The deserialized record.79        :rtype: ~azure.identity.AuthenticationRecord80        """81 82        deserialized = json.loads(data)83 84        version = deserialized.get("version")85        if version not in SUPPORTED_VERSIONS:86            raise ValueError(87                'Unexpected version "{}". This package supports these versions: {}'.format(version, SUPPORTED_VERSIONS)88            )89 90        return cls(91            authority=deserialized["authority"],92            client_id=deserialized["clientId"],93            home_account_id=deserialized["homeAccountId"],94            tenant_id=deserialized["tenantId"],95            username=deserialized["username"],96        )97 98    def serialize(self) -> str:99        """Serialize the record.100 101        :return: The serialized record.102        :rtype: str103        """104 105        record = {106            "authority": self._authority,107            "clientId": self._client_id,108            "homeAccountId": self._home_account_id,109            "tenantId": self._tenant_id,110            "username": self._username,111            "version": "1.0",112        }113 114        return json.dumps(record)115 
codekingpro/portable-devtools · Team Ai