-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadb2c-silent-sample.py
More file actions
38 lines (32 loc) · 1.31 KB
/
adb2c-silent-sample.py
File metadata and controls
38 lines (32 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import msal
import requests
import urllib3
import json
# Azure AD B2Cの設定
tenant_name = '<<TENANT_NAME>>'
client_id = '<<CLIENT_ID>>'
client_secret = '<<CLIENT_SECRET>>'
authority = f'https://{tenant_name}.b2clogin.com/{tenant_name}.onmicrosoft.com/b2c_1_fjcloud_genai_susi'
scopes = [f'https://{tenant_name}.onmicrosoft.com/{client_id}/.default']
app = msal.ConfidentialClientApplication(client_id, authority=authority, client_credential=client_secret)
result = app.acquire_token_for_client(scopes=scopes)
if "access_token" in result:
print("Access token:", result["access_token"])
else:
print("Error:", result.get("error"), result.get("error_description"))
api = f"https://{tenant_name}.generative-ai-platform.cloud.global.fujitsu.com/api/v1/chats"
headers = {
"Content-Type": "application/json",
"x-user": "application",
"Authorization": f"Bearer {result['access_token']}"
}
print(api)
print(headers)
print("------------")
try:
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
response = requests.get(api, headers=headers, verify=False) #必要に応じて証明書チェックを無効化
data = json.loads(response.text)
print(json.dumps(data, indent=2))
except requests.exceptions.SSLError as e:
print(f"SSL Error: {e}")