@@ -8,19 +8,7 @@ JWT (JSON Web Token) authentication is the primary authentication mechanism for
88
99Migrating from Basic Authentication to JWT provides enhanced security, better performance, and fine-grained access control. Here's how to migrate:
1010
11- ### Step 1: Generate a JWT Token
12-
13- ``` bash
14- curl -X POST " https://api.sms-gate.app/3rdparty/v1/auth/token" \
15- -u " username:password" \
16- -H " Content-Type: application/json" \
17- -d ' {
18- "ttl": 3600,
19- "scopes": ["messages:send", "messages:read"]
20- }'
21- ```
22-
23- ### Step 2: Update Your Code
11+ ### Step 1: Update Your Code
2412
2513Replace Basic Auth with JWT Bearer tokens:
2614
@@ -29,7 +17,7 @@ Replace Basic Auth with JWT Bearer tokens:
2917 response = requests.post(
3018 " https://api.sms-gate.app/3rdparty/v1/messages" ,
3119 auth = (" username" , " password" ),
32- json = {" recipient " : " +1234567890" , " message " : " Hello world!" }
20+ json = {" phoneNumbers " : [ " +1234567890" ] , " textMessage " : { " text " : " Hello world!" } }
3321 )
3422 ```
3523
@@ -53,11 +41,11 @@ Replace Basic Auth with JWT Bearer tokens:
5341 " Authorization" : f " Bearer { access_token} " ,
5442 " Content-Type" : " application/json"
5543 },
56- json = {" recipient " : " +1234567890" , " message " : " Hello world!" }
44+ json = {" phoneNumbers " : [ " +1234567890" ] , " textMessage " : { " text " : " Hello world!" } }
5745 )
5846 ```
5947
60- ### Step 3 : Implement Token Management
48+ ### Step 2 : Implement Token Management
6149
6250- ** Token Refresh** : Implement automatic token refresh before expiration
6351- ** Error Handling** : Handle 401/403 errors gracefully
@@ -153,7 +141,6 @@ class SMSGatewayClient:
153141 - Refresh tokens 5-10 minutes before expiration
154142 - Implement exponential backoff for failed refresh attempts
155143 - Store tokens securely (not in client-side code)
156- - Monitor token usage patterns
157144
158145## 🛡️ How do I revoke a JWT token?
159146
@@ -168,35 +155,6 @@ curl -X DELETE "https://api.sms-gate.app/3rdparty/v1/auth/token/{jti}" \
168155
169156Where ` {jti} ` is the token ID from the token response.
170157
171- ## 🔒 Is JWT authentication more secure than Basic Auth?
172-
173- Yes, JWT authentication provides several security advantages over Basic Authentication:
174-
175- ### Security Benefits
176-
177- 1 . ** No Credential Transmission** : JWT tokens don't transmit username/password with each request
178- 2 . ** Fine-grained Access Control** : Scopes limit what each token can do
179- 3 . ** Short-lived Tokens** : Tokens expire automatically, reducing the impact of compromise
180- 4 . ** Digital Signatures** : Tokens are cryptographically signed to prevent tampering
181- 5 . ** No Session Storage** : Stateless authentication reduces server-side attack surface
182-
183- ### Security Considerations
184-
185- While JWT is more secure than Basic Auth, proper implementation is crucial:
186-
187- - ** Strong Secrets** : Use at least 32-character random secrets
188- - ** HTTPS Only** : Always transmit tokens over encrypted connections
189- - ** Short TTLs** : Use the shortest practical expiration time
190- - ** Scope Limitation** : Request only necessary scopes
191- - ** Secure Storage** : Store tokens securely on the server side
192-
193- !!! tip "Security Best Practices"
194- - Implement token revocation for compromised tokens
195- - Monitor token generation and usage patterns
196- - Use HTTPS for all API communications
197- - Regularly rotate JWT secrets
198- - Implement proper error handling for authentication failures
199-
200158## 🔐 "Invalid token" JWT Error
201159
202160The "invalid token" error occurs when the JWT token is malformed, has an incorrect signature, or cannot be validated by the server.
@@ -349,10 +307,9 @@ When migrating from Basic Authentication to JWT, you may encounter various issue
349307
350308### Common Issues
351309
352- 1 . ** Mixed Authentication** : Some requests use Basic Auth while others use JWT
353- 2 . ** Token Generation Errors** : Unable to generate JWT tokens
354- 3 . ** Permission Errors** : JWT tokens don't have the same permissions as Basic Auth
355- 4 . ** Code Compatibility** : Existing code doesn't work with JWT authentication
310+ 1 . ** Token Generation Errors** : Unable to generate JWT tokens
311+ 2 . ** Permission Errors** : JWT tokens don't have the same permissions as Basic Auth
312+ 3 . ** Code Compatibility** : Existing code doesn't work with JWT authentication
356313
357314### Troubleshooting Steps
358315
0 commit comments