-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpasso7_isc_client.py
More file actions
73 lines (57 loc) · 2.57 KB
/
Copy pathpasso7_isc_client.py
File metadata and controls
73 lines (57 loc) · 2.57 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
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
"""
PASSO 7 (cliente) - Fala com o ISC "como em producao".
Fluxo igual ao de um tenant real do SailPoint ISC:
1. Autentica via OAuth2 (client_credentials) e recebe um access_token.
2. Usa o token (header Authorization: Bearer ...) para chamar /v3.
3. Lista identities e cria um access request.
PARA APONTAR PARA UM TENANT REAL, bastaria trocar:
BASE_URL -> https://SEU-TENANT.api.identitynow.com
CLIENT_ID / CLIENT_SECRET -> credenciais geradas no painel do ISC
(O SDK oficial 'sailpoint' faz esse mesmo fluxo por baixo dos panos.)
IMPORTANTE: o mock do PASSO 7 precisa estar no ar:
Terminal 1: uvicorn passo7_isc_mock_api:app --reload --port 8003
Terminal 2: python passo7_isc_client.py
"""
import requests
BASE_URL = "http://127.0.0.1:8003"
CLIENT_ID = "lab-client-id"
CLIENT_SECRET = "lab-client-secret"
def obter_token() -> str:
"""Passo OAuth2: troca client_id + client_secret por um access_token."""
resp = requests.post(
f"{BASE_URL}/oauth/token",
data={
"grant_type": "client_credentials",
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET,
},
timeout=5,
)
resp.raise_for_status()
return resp.json()["access_token"]
def main():
try:
token = obter_token()
print(f"Autenticado. Token (inicio): {token[:8]}...")
# O header que acompanha TODA chamada protegida no ISC.
headers = {"Authorization": f"Bearer {token}"}
print("\nIdentities no ISC:")
ids = requests.get(f"{BASE_URL}/v3/identities", headers=headers, timeout=5).json()
for i in ids:
print(f" - {i['name']:14} | {i['attributes']['department']:11} | {i['lifecycleState']}")
print("\nCriando access request para ana.souza...")
corpo = {
"requestedFor": ["2c918085"],
"requestedItems": [{"type": "ACCESS_PROFILE", "id": "AD-Grupo-Financeiro"}],
}
ar = requests.post(f"{BASE_URL}/v3/access-requests", json=corpo, headers=headers, timeout=5).json()
print(f" -> request {ar['id']} criado com status {ar['status']}")
# Demonstra a seguranca: sem token, o ISC recusa.
print("\nTentando sem token (deve falhar com 401):")
r = requests.get(f"{BASE_URL}/v3/identities", timeout=5)
print(f" -> status {r.status_code} (esperado 401/403)")
except requests.exceptions.ConnectionError:
print("ERRO: nao consegui conectar no mock do ISC.")
print(" Suba: uvicorn passo7_isc_mock_api:app --reload --port 8003")
if __name__ == "__main__":
main()