Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/anaconda_auth/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ def logout(config: Optional[AnacondaAuthSite] = None) -> None:
# domains.
try:
token_info = TokenInfo.load(domain="anaconda.cloud")

token_info.delete()
except TokenNotFoundError:
pass
Expand Down
14 changes: 13 additions & 1 deletion src/anaconda_auth/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,19 @@ def auth_key(at: Optional[str] = None) -> None:


@app.command(name="logout")
def auth_logout(at: Optional[str] = None) -> None:
def auth_logout(
at: Optional[str] = None,
invalidate: bool = typer.Option(
False, "--invalidate", "-i", help="Invalidate Api Key."
),
) -> None:
"""Logout"""
_override_default_site(at)

if invalidate:
token_info = TokenInfo.load()
client = BaseClient()
response = client.delete(f"/api/auth/api-keys/{token_info.api_key_kid}")
response.raise_for_status()

logout()
10 changes: 10 additions & 0 deletions src/anaconda_auth/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,16 @@ class TokenInfo(BaseModel):
repo_tokens: List[RepoToken] = []
version: Optional[int] = TOKEN_INFO_VERSION

@property
def decoded_api_key(self) -> dict:
return jwt.decode(
self.api_key, algorithms=["RS256"], options={"verify_signature": False}
)

@property
def api_key_kid(self) -> str:
return self.decoded_api_key.get("kid")

@classmethod
def _decode(cls, keyring_data: str) -> dict:
decoded_bytes = base64.b64decode(keyring_data)
Expand Down
Loading