Skip to content

Commit 8d5dd44

Browse files
authored
Merge branch 'SAP:main' into main
2 parents 3f189f5 + e6f85fa commit 8d5dd44

File tree

2 files changed

+222
-30
lines changed

2 files changed

+222
-30
lines changed

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
*.pyc
33

44
# IntelliJ IDEA
5-
.idea/workspace.xml
6-
.idea/tasks.xml
7-
.idea/dictionaries/
5+
.idea
86
.DS_Store
97

108
getUserInfo.py

README.md

Lines changed: 221 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,232 @@
1-
# Gigya SDK for Python
2-
Learn more: https://developers.gigya.com/display/GD/Python
1+
# Python SDK
2+
*SAP Customer Data Cloud (Gigya)*
33

4-
## Description
5-
The Python SDK, provides a Python interface for the Gigya API.
6-
The library makes it simple to integrate Gigya services in your Python application.
4+
### Description
5+
The Python SDK provides a Python interface
6+
for the Gigya API. The library makes it simple to integrate Gigya services
7+
in your Python application. This document is a practical step-by-step guide
8+
for programmers who wish to integrate the Gigya service into their Python
9+
application. Follow the steps below to get started,
10+
and use the [Library Reference](https://help.sap.com/viewer/DRAFT/8b8d6fffe113457094a17701f63e3d6a/GIGYA/en-US/416a3f1f70b21014bbc5a10ce4041860.html) while implementing.
711

8-
## Requirements
9-
[Python 2.7 and 3](https://www.python.org/downloads/)
12+
```
13+
Note: Python 2.7.x and 3 are supported.
14+
```
15+
16+
##Library Guide
1017

11-
## Download and Installation
12-
* Clone the repo.
13-
* Open the Project.
18+
Please follow these steps to integrate this library in your Python application:
1419

15-
## Configuration
16-
* [Obtain a Gigya APIKey and Secret key](https://developers.gigya.com/display/GD/Python#Python-ObtainingGigya'sAPIKeyandSecretkey).
17-
* Copy the GSSDK.py file to your Python application path.
18-
* Import the GSSDK.py file into your application:
19-
```Python
20+
1. Download the zip file and extract it
21+
2. Obtain Gigya's APIKey and Secret key.
22+
3. Import GSSDK.py library into your application.
23+
4. Log the user in.
24+
5. Use Gigya's API - Send Requests.
25+
6. Optional: incorporate security measures.
26+
27+
### Obtain Gigya's APIKey and Secret key
28+
Making API calls requires an API Key and a Secret Key which are obtained from the Site DashboardInformation published on non-SAP site page on the Gigya website. The Secret Key must be kept secret and never transmitted to an untrusted client or over insecure networks. The API Key and the Secret Key are required parameter in each request (further ahead in this document you will find guidance for sending requests).
29+
30+
### Importing the GSSDK.py Library into Your Application
31+
To get started, you'll need to import Gigya Python SDK to your application:
32+
33+
Copy the GSSDK.py file to your Python application path.
34+
Import the GSSDK.py file into your application:
35+
```python
2036
from GSSDK import *
2137
```
22-
* Start using according to [documentation](https://developers.gigya.com/display/GD/Python).
38+
You should now be able to use the SDK in your project.
39+
40+
### Logging the User in
41+
The first interaction with Gigya must always be logging in.
42+
If the user is not logged in, you cannot access their social profile nor perform social
43+
activities, such as setting their status. Sending requests requires an identified Gigya user
44+
(the identification of whom is performed using the UID parameter) with an active session.
45+
A user session is created when a user logs in via the Gigya service. Log users in through
46+
your client application using our Web SDK methods: socialize.login,
47+
socialize.notifyLogin, or using our ready-made Social Login UI.
48+
49+
To learn more about the login process, see [Social Login](https://help.sap.com/viewer/DRAFT/8b8d6fffe113457094a17701f63e3d6a/GIGYA/en-US/417916f470b21014bbc5a10ce4041860.html).
50+
51+
[LoginDiagram]: https://help.sap.com/doc/DRAFT/8b8d6fffe113457094a17701f63e3d6a/GIGYA/en-US/loio40c2081f70b21014bbc5a10ce4041860_LowRes.gif "Login Diagram"
52+
53+
###Sending a Request
54+
After you have logged in the user, you may use the GSRequest class to access the user profile and perform various activities. This is implemented using GSRequest's send method. The following code sends a request to set the current user's status to "I feel great":
55+
56+
```python
57+
58+
# Define the API-Key and Secret key (the keys can be obtained from your site setup page on Gigya's website).
59+
apiKey = "PUT-YOUR-APIKEY-HERE"
60+
secretKey = "PUT-YOUR-SECRET-KEY-HERE"
61+
62+
# Step 1 - Defining the request and adding parameters
63+
method = "socialize.setStatus"
64+
params={"uid":"PUT-UID-HERE", "status":"I feel great"} # Set "uid" to the user's ID, and "status" to "I feel great"
65+
request = GSRequest(apiKey,secretKey,method,params)
66+
67+
# Step 2 - Sending the request
68+
response = request.send()
69+
70+
# Step 3 - handling the request's response.
71+
if (response.getErrorCode()==0):
72+
# SUCCESS! response status = OK
73+
print "Success in setStatus operation."
74+
else:
75+
# Error
76+
print "Got error on setStatus: " + response.getErrorMessage()
77+
# You may also log the response: response.getLog()
78+
```
79+
80+
### Step 1: Defining the Request and Adding Parameters
81+
Create a GSRequest instance:
82+
83+
```python
84+
85+
method = "socialize.setStatus"
86+
params={"uid":"PUT-UID-HERE", "status":"I feel great"} # Set "uid" to the user's ID, and "status" to "I feel great"
87+
request = GSRequest(apiKey,secretKey,method,params)
88+
```
89+
The parameters of the GSRequest are:
90+
91+
1. apiKey
92+
2. secretKey
93+
```
94+
Note:
95+
For information about obtaining these keys, see above.
96+
```
97+
3. method - the Gigya API method to call, including namespace. For example: 'socialize.getUserInfo'. Please refer to the REST API reference for the list of available methods.
98+
4. params - In this case the uid and status.
99+
<pre>
100+
Note:
101+
In the <a href="https://help.sap.com/viewer/DRAFT/8b8d6fffe113457094a17701f63e3d6a/GIGYA/en-US/41735f5270b21014bbc5a10ce4041860.html">REST API reference</a> you may find the list of available Gigya API methods and the list of parameters per each method.
102+
</pre>
103+
104+
### Step 2: Sending the Request
105+
Execute GSRequest's send method:
106+
107+
```python
108+
response = request.send()
109+
```
110+
The method returns a GSResponse object, which is handled in the next step.
111+
112+
```
113+
Note:
114+
By default, requests to Gigya APIs are sent using the "us1.gigya.com" domain. If your site has been set up to use another of Gigya's data centers, you must specify that the request should be sent to that specific data center by adding the following line of code before calling the Send method:
115+
request.setAPIDomain("<Data_Center>")
116+
```
117+
118+
119+
Where *<Data_Center>* is:
120+
121+
**us1.gigya.com** - For the US data center.<br>
122+
**eu1.gigya.com** - For the European data center.<br>
123+
**au1.gigya.com** - For the Australian data center.<br>
124+
**ru1.gigya.com** - For the Russian data center.<br>
125+
**cn1.gigya-api.cn** - For the Chinese data center.<br>
126+
127+
If you are not sure of your site's data center, see [Finding Your Data Center](https://help.sap.com/viewer/DRAFT/8b8d6fffe113457094a17701f63e3d6a/GIGYA/en-US/41573b6370b21014bbc5a10ce4041860.html).
128+
129+
See the [GSRequest documentation](https://help.sap.com/viewer/DRAFT/8b8d6fffe113457094a17701f63e3d6a/GIGYA/en-US/41467b5670b21014bbc5a10ce4041860.html) for more information.
130+
131+
### Step 3: Handling the Response
132+
Use the GSResponse object to check the status of the response, and to receive response data:
133+
134+
```python
135+
if (response.getErrorCode()==0):
136+
# SUCCESS! response status = OK
137+
print "Success in setStatus operation."
138+
else:
139+
# Error
140+
print "Got error on setStatus: " + response.getErrorMessage()
141+
# You may also log the response: response.getLog()
142+
# You may also log the response: response.getLog()
143+
```
144+
The [GSResponse](https://help.sap.com/viewer/DRAFT/8b8d6fffe113457094a17701f63e3d6a/GIGYA/en-US/4146c7ed70b21014bbc5a10ce4041860.html) object includes data fields. For each request method,
145+
the response data fields are different.
146+
Please refer to the Gigya REST API reference for the list of response data fields per method.
147+
148+
For example - handling a [socialize.getUserInfo](https://help.sap.com/viewer/DRAFT/8b8d6fffe113457094a17701f63e3d6a/GIGYA/en-US/417637a470b21014bbc5a10ce4041860.html) response:
23149

24-
## Limitations
25-
None
150+
The response of 'socialize.getUserInfo' includes a 'user' object.
151+
```python
152+
# Sending 'socialize.getUserInfo' request
153+
params = {"uid", "PUT-UID-HERE"} // set the "uid" parameter to user's ID
154+
request = GSRequest(apiKey,secretKey,"socialize.getUserInfo",params)
155+
response = request.send()
156+
157+
# Handle 'getUserInfo' response
158+
if (response.getErrorCode() == 0):
159+
# SUCCESS! response status = OK
160+
nickname = response.getObject("nickname")
161+
age = response.getObject("age")
162+
print "User name: " + nickname + " The user's age: " + age
163+
else:
164+
print "Got error on getUserInfo: " + response.getErrorMessage()
165+
# You may also log the response: response.getLog()
166+
```
26167

27-
## Known Issues
28-
None
168+
### Optional - Incorporating Security Measures
29169

30-
## How to obtain support
31-
Via SAP standard support.
32-
https://developers.gigya.com/display/GD/Opening+A+Support+Incident
170+
#### Validating Signatures
171+
Signature validation is only necessary and supported when validating the signature of a response that was received
172+
on the client side and then passed to the server.
173+
Server-to-server calls do not contain the *UIDSignature* or *signatureTimestamp* properties in the response.
33174

34-
## Contributing
35-
Via pull request to this repository.
175+
The Gigya service supports a mechanism to verify the authenticity of the Gigya processes,
176+
to prevent fraud. When Gigya sends you information about a user,
177+
your server needs to know that it is actually coming from Gigya.
178+
For that cause, Gigya attaches a cryptographic signature to the responses that include user information.
179+
We highly recommend validating the signature.
180+
The [SigUtils](https://help.sap.com/viewer/DRAFT/8b8d6fffe113457094a17701f63e3d6a/GIGYA/en-US/4147019770b21014bbc5a10ce4041860.html)
181+
class is a utility class for generating and validating signatures.
36182

37-
## To-Do (upcoming changes)
38-
None
183+
For example, Gigya signs the [socialize.getUserInfo](https://help.sap.com/viewer/DRAFT/8b8d6fffe113457094a17701f63e3d6a/GIGYA/en-US/417637a470b21014bbc5a10ce4041860.html) method response.
184+
The following code validates the signature received with the 'socialize.getUserInfo' method response:
185+
186+
```python
187+
# Handle 'socialize.getUserInfo' response
188+
if (response.getErrorCode()==0):
189+
# SUCCESS! response status = OK
190+
# Validate the signature:
191+
valid = SigUtils.validateUserSignature(response.getObject("UID"),response.getObject("signatureTimestamp"),
192+
secretKey,response.getObject("UIDSignature"))
193+
if (valid):
194+
print "signature is valid"
195+
else:
196+
print "signature is not valid"
197+
```
198+
The parameters of the [validateUserSignature](https://help.sap.com/viewer/DRAFT/8b8d6fffe113457094a17701f63e3d6a/GIGYA/en-US/4147019770b21014bbc5a10ce4041860.html) method are:
199+
200+
1. UID - the user's unique ID
201+
2. signatureTimestamp - The GMT time of the response in UNIX time format (i.e. the number of seconds since Jan. 1st 1970). The method validates that the timestamp is within five minutes of the current time on your server.
202+
3. secretKey - The key to verification is your partner's "**Secret Key**". Your secret key (provided in BASE64 encoding) is located at the bottom of the DashboardInformation published on non-SAP site section on Gigya's website (Read more above).
203+
4. UIDSignature - the cryptographic signature.
204+
All the parameters, with the exception of the secretKey, should be taken from the 'User' object received with the 'getUserInfo' method response.
205+
206+
The method returns a Boolean value, signifying if the signature is valid or not.
207+
208+
In a similar fashion, when using the 'getFriendsInfo' method, The method response include a collection of 'Friend' objects. Each Friend object will be signed with a cryptographic signature. To verify the signature of a friend object, please use the validateFriendSignature method.
209+
210+
### Sending Requests over HTTPS
211+
If you would like to use Gigya service over HTTPS, you will need to do the following:
212+
213+
Create a GSRequest object using the constructor that receives five parameters.
214+
The additional fifth parameter is a Boolean parameter named useHTTPS. Set this parameter to be **true**.
215+
216+
### Appendix - Publish User Action Example
217+
The following code sample sends a request to publish a user action to the newsfeed stream on all the connected providers which support this feature.
218+
219+
The method has a complex parameter called which defines the user action data to be published. To define the userAction parameter create a JSON object and fill it with data. Fill the object with data as shown in the example below:
220+
221+
```python
222+
# Publish User Action
223+
224+
# Defining the userAction parameter
225+
userAction = {"title":"","userMessage":"This is my user message","description":"This is my description",
226+
"linkBack":"http://google.com",{\"src\":\"http://www.f2h.co.il/logo.jpg\", \"href\":\"http://www.f2h.co.il\",\"type\":\"image\"}}
227+
228+
# Sending 'socialize.publishUserAction' request
229+
params = {"userAction":userAction, "uid":"PUT-UID-HERE"}
230+
request = GSRequest("PUT-YOUR-APIKEY-HERE", "PUT-YOUR-SECRET-KEY-HERE", "socialize.publishUserAction", params)
231+
response = request.send()
232+
```

0 commit comments

Comments
 (0)