You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Basalam Python SDK supports multiple authentication methods to suit different use cases. This guide covers all available authentication options with practical examples.
3
+
The SDK supports three main authentication methods, all managed via authentication objects implementing the `BaseAuth` interface:
4
4
5
-
All authentication is handled through authentication objects that implement the `BaseAuth` interface. The SDK supports three main authentication methods:
5
+
-**Personal Access Token** – for personal or dedicated applications
6
+
-**Authorization Code Flow** – for user authentication scenarios on third-party platforms
7
+
-**Client Credentials** – for applications with legal/organizational access
6
8
7
-
1.**Personal Token** - For applications with existing tokens
8
-
2.**Authorization Code Flow** - For user authentication scenarios
9
-
3.**Client Credentials** - For server-to-server applications
9
+
For more information about these methods, refer to the [Authentication in Basalam API](../../quick-start#auth) document.
Use this method when you already have valid access and refresh tokens.
22
-
23
-
### Basic Usage
21
+
For personal applications for a booth or user, after [getting your token from the developer panel](https://developers.basalam.com/panel/tokens), you can manage it using `PersonalToken`.
24
22
25
23
```python
26
24
from basalam_sdk import BasalamClient, PersonalToken
27
25
28
-
# Initialize with existing tokens
29
-
auth = PersonalToken(
30
-
token="your_existing_access_token",
31
-
refresh_token="your_existing_refresh_token"
32
-
)
33
-
34
-
# Create authenticated client
35
-
client = BasalamClient(auth=auth)
36
-
```
37
-
38
-
### Advanced Configuration
39
-
40
-
```python
41
-
from basalam_sdk import PersonalToken, BasalamConfig
## Authorization Code Flow (For User Authentication)
36
+
# Get current user info
37
+
user = client.get_current_user()
38
+
return user
39
+
```
78
40
79
-
Use this method when you need to authenticate on behalf of a user.
41
+
## Authorization Code Flow (for user authentication)
80
42
81
-
### Step-by-Step Process
43
+
When building a third-party app requiring access from users, after [creating a client in the developer panel](https://developers.basalam.com/panel/clients), use the `AuthorizationCode` class to manage the flow.
82
44
83
45
```python
84
46
from basalam_sdk import BasalamClient, AuthorizationCode, Scope
# ... store token_info.access_token, token_info.refresh_token
161
-
101
+
102
+
#Securely store tokens
103
+
# ... save token_info.access_token, token_info.refresh_token
104
+
162
105
return"Authentication successful!"
163
106
```
164
107
165
-
## Client Credentials (Recommended for Server-to-Server)
108
+
## Client Credentials
166
109
167
-
Use this method for server-to-server applications where you have a client ID and secret.
110
+
To use APIs requiring organizational identity (e.g., Wallet), after [client authentication](../../quick-start#client_credentials) using `grant_type="client_credentials"`, use `ClientCredentials`.
168
111
169
-
### Basic Setup
112
+
### Initial Configuration
170
113
171
114
```python
172
115
from basalam_sdk import BasalamClient, ClientCredentials
# Get token – will reuse existing one if not expired
163
+
token_info =await auth.get_token()
248
164
249
-
```python
250
-
asyncdefrefresh_token_example():
251
-
auth = AuthorizationCode(
252
-
client_id="your-client-id",
253
-
client_secret="your-client-secret",
254
-
redirect_uri="https://your-app.com/callback"
255
-
)
256
-
257
-
# Get initial token
258
-
await auth.get_token(code="authorization_code")
259
-
260
-
# Later, refresh the token
261
-
refreshed_token =await auth.get_token()
262
-
263
-
return refreshed_token
165
+
return token_info
264
166
```
265
167
266
168
## Scopes
267
169
268
-
Scopes define what permissions your application has. Available scopes include:
170
+
Scopes define the permissions granted to your app. In addition to the [Scopes doc](https://developers.basalam.com/scopes), the SDK provides scopes via the `Scope` class. Available scopes include:
269
171
270
172
```python
271
173
from basalam_sdk import Scope
@@ -293,9 +195,4 @@ auth = ClientCredentials(
293
195
Scope.CUSTOMER_ORDER_READ
294
196
]
295
197
)
296
-
```
297
-
298
-
## Next Steps
299
-
300
-
-[Wallet Service](./services/wallet.md) - Manage user balances
0 commit comments