microsoft/TypeAgent

Public

mirrored from https://github.com/microsoft/TypeAgentAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
aeb802854fa1b0f1aa92f4ccbf839cb2a48ad3cb

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

python/ta/auth.py

24lines · modecode

1#!/usr/bin/env python
2# Copyright (c) Microsoft Corporation.
3# Licensed under the MIT License.
4
5"""Utility to set AZURE_OPENAI_API_KEY to a valid token.
6
7Usage: eval `./auth.py`
8
9NOTE: The token is only valid for a short time.
10"""
11
12import sys
13
14from azure.identity import DeviceCodeCredential
15
16save_stdout = sys.stdout
17sys.stdout = sys.stderr
18
19# TODO: Do something non-interactive.
20credential = DeviceCodeCredential()
21token = credential.get_token("https://cognitiveservices.azure.com/.default")
22
23sys.stdout = save_stdout
24print(f"export AZURE_OPENAI_API_KEY={token.token}")
25