forked from OpenBankProject/Hello-OBP-DirectLogin-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello_set_entitlements.py
69 lines (53 loc) · 1.87 KB
/
hello_set_entitlements.py
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
# -*- coding: utf-8 -*-
from __future__ import print_function # (at top of module)
import sys, time, requests
# Note: in order to use this example, you need to have at least one account
# that you can send money from (i.e. be the owner).
# All properties are now kept in one central place
from props.danskebank import *
#from props.socgen import *
ROLES=['CanQueryOtherUser']
ENTITLEMENTS=['CanQueryOtherUser']
# You probably don't need to change those
import lib.obp
obp = lib.obp
obp.setBaseUrl(BASE_URL)
obp.setApiVersion(API_VERSION)
# Login and set authorized token
obp.login(USERNAME, PASSWORD, CONSUMER_KEY)
# Get all entitlements
print ("")
print (" --- Get user's entitlements")
all_entitlements = obp.getAllEntitlements()
print ("all entitlements:\n{0}".format(all_entitlements))
# Get current user
print ("")
print (" --- Get current user")
user = obp.getCurrentUser()
user_id = user['user_id']
print ("current user id: {0}".format(user))
# Get user entitlements
print ("")
print (" --- Get user's entitlements")
entitlements = obp.getAllEntitlements()
if 'error' not in entitlements:
print ("user {0} entitlements:\n{1}".format(user_id, entitlements))
else:
# Add CanGetEntitlementsForAnyUserAtOneBank entitlement
print ("")
print (" --- Add CanGetEntitlementsForAnyUserAtAnyBank entitlement")
response = obp.addEntitlement('CanGetEntitlementsForAnyUserAtAnyBank', user_id, OUR_BANK)
print ("response:\n{0}".format(response))
# Add system roles from list
for role in ROLES:
print ("")
print (" --- Add {0} role".format(role))
response = obp.addRole(role, user_id)
print ("response:\n{0}".format(response))
# Add entitlements from list
for entitlement in ENTITLEMENTS:
print ("")
print (" --- Add {0} entitlement".format(entitlement))
response = obp.addEntitlement(entitlement, user_id, OUR_BANK)
print ("response:\n{0}".format(response))
print ("")