Skip to content

Commit 0f0df95

Browse files
committed
[blog] improve jwt post
1 parent a0d6ebb commit 0f0df95

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed
85.8 KB
Loading

docs/blog/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ Welcome to the SMSGate blog! Here you'll find the latest news, updates, and tech
55
## Categories
66

77
- [**API**](/blog/category/api/): Technical documentation and integration guides for RESTful API endpoints
8+
- [**Authentication**](/blog/category/authentication/): Strategies and techniques for secure user authentication and authorization
89
- [**Best Practices**](/blog/category/best-practices/): Recommended approaches and optimization techniques for common scenarios
910
- [**Documentation**](/blog/category/documentation/): Comprehensive reference materials and detailed platform guides
1011
- [**Features**](/blog/category/features/): In-depth explorations of platform capabilities and advanced functionality
1112
- [**IoT**](/blog/category/iot/): Use cases and implementation strategies for Internet of Things applications
13+
- [**Security**](/blog/category/security/): Tips and best practices for secure communication and data protection
1214
- [**Tutorials**](/blog/category/tutorials/): Step-by-step implementation guides for specific workflows
1315

1416
---

docs/blog/posts/2025-12-09_jwt-authentication-migration.md

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ Enter JWT (JSON Web Token) authentication—a token-based authentication mechani
1616

1717
<!-- more -->
1818

19+
<center>
20+
<img src="/assets/blog/jwt-authentication-migration.png" alt="JWT Authentication Migration">
21+
</center>
22+
1923
## 🎯 Why JWT Authentication?
2024

2125
### The Basic Auth Problem
@@ -52,12 +56,12 @@ JWT authentication addresses these concerns with a modern, secure approach:
5256

5357
A JWT token consists of three base64-encoded parts separated by dots:
5458

55-
```
59+
```text
5660
Header.Payload.Signature
5761
```
5862

5963
**Example Token:**
60-
```
64+
```text
6165
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyMTIzIiwic2NvcGVzIjpbIm1lc3NhZ2VzOnNlbmQiXSwiZXhwIjoxNzMzNzg1MjAwfQ.signature_here
6266
```
6367

@@ -175,9 +179,10 @@ To generate a JWT token, make a POST request to the token endpoint using your ex
175179
**Response:**
176180
```json
177181
{
178-
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
182+
"id": "nHDAWaPS6zv3itRUpM9ko",
179183
"token_type": "Bearer",
180-
"expires_at": "2025-12-09T15:30:00Z"
184+
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
185+
"expires_at": "2025-12-10T03:03:09Z"
181186
}
182187
```
183188

@@ -471,7 +476,7 @@ admin_token = get_token(scopes=["all:any"])
471476
Revoke tokens when no longer needed:
472477

473478
```python
474-
def revoke_token(token):
479+
def revoke_token(token, jti):
475480
"""Revoke a JWT token"""
476481
response = requests.delete(
477482
f"https://api.sms-gate.app/3rdparty/v1/auth/token/{jti}",
@@ -584,34 +589,34 @@ else:
584589
Use this checklist for a smooth transition:
585590

586591
- [ ] **Week 1: Preparation**
587-
- [ ] Review JWT documentation
588-
- [ ] Test token generation in development
589-
- [ ] Identify all services using Basic Auth
590-
- [ ] Plan scope requirements per service
592+
- [ ] Review JWT documentation
593+
- [ ] Test token generation in development
594+
- [ ] Identify all services using Basic Auth
595+
- [ ] Plan scope requirements per service
591596

592597
- [ ] **Week 2: Implementation**
593-
- [ ] Implement token management class
594-
- [ ] Add JWT support to existing clients
595-
- [ ] Create dual-auth fallback mechanism
596-
- [ ] Set up monitoring for auth errors
598+
- [ ] Implement token management class
599+
- [ ] Add JWT support to existing clients
600+
- [ ] Create dual-auth fallback mechanism
601+
- [ ] Set up monitoring for auth errors
597602

598603
- [ ] **Week 3: Testing**
599-
- [ ] Test in staging environment
600-
- [ ] Verify all scopes work correctly
601-
- [ ] Load test JWT performance
602-
- [ ] Document token refresh flows
604+
- [ ] Test in staging environment
605+
- [ ] Verify all scopes work correctly
606+
- [ ] Load test JWT performance
607+
- [ ] Document token refresh flows
603608

604609
- [ ] **Week 4: Deployment**
605-
- [ ] Deploy JWT support to production
606-
- [ ] Monitor error rates
607-
- [ ] Gradually shift traffic to JWT
608-
- [ ] Keep Basic Auth as fallback
610+
- [ ] Deploy JWT support to production
611+
- [ ] Monitor error rates
612+
- [ ] Gradually shift traffic to JWT
613+
- [ ] Keep Basic Auth as fallback
609614

610615
- [ ] **Week 5+: Cleanup**
611-
- [ ] Verify 100% JWT usage
612-
- [ ] Remove Basic Auth code
613-
- [ ] Update all documentation
614-
- [ ] Archive Basic Auth credentials
616+
- [ ] Verify 100% JWT usage
617+
- [ ] Remove Basic Auth code
618+
- [ ] Update all documentation
619+
- [ ] Archive Basic Auth credentials
615620

616621
## 🎉 Conclusion
617622

0 commit comments

Comments
 (0)