Authentication

Authentication APIs

Basic Authentication là phương thức xác thực đơn giản nhất trong HTTP.

Cách hoạt động:

  • Client gửi username và password được mã hóa Base64 trong HTTP header
  • Format: Authorization: Basic base64(username:password)
  • Server giải mã và xác thực thông tin đăng nhập

Ưu điểm: Đơn giản, dễ triển khai

Nhược điểm: Không bảo mật cao nếu không dùng HTTPS, phải gửi credentials mỗi request

Endpoint: https://material.playwrightvn.com/api/authentication/basic_auth.php

Method: GET

Credentials: bba / demo_password

Response:

Click "Test Basic Auth" to see response

JWT (JSON Web Token) là một chuẩn mở để truyền tải thông tin xác thực một cách an toàn.

Cách hoạt động:

  • Client gửi username/password để đăng nhập
  • Server xác thực và trả về JWT token
  • Client lưu token và gửi kèm trong header cho các request tiếp theo
  • Format: Authorization: Bearer <token>

Cấu trúc JWT: Header.Payload.Signature

Ưu điểm: Stateless, scalable, có thể chứa thông tin user

Nhược điểm: Token có thể bị đánh cắp, khó thu hồi token trước khi hết hạn

Endpoint Login: https://material.playwrightvn.com/api/authentication/jwt_login.php

Method: POST

Credentials: bba / demo_password

Response:

Click "Test JWT Login" to see response

Kiểm tra lại token

Endpoint: https://material.playwrightvn.com/api/authentication/jwt_auth.php

Method: GET

Authentication type: Bearer token

Session Authentication sử dụng session được lưu trên server và cookie trên client.

Cách hoạt động:

  • Client gửi username/password để đăng nhập
  • Server tạo session và lưu trữ thông tin user
  • Server trả về session ID qua cookie
  • Browser tự động gửi cookie trong các request tiếp theo
  • Server kiểm tra session ID để xác thực user

Ưu điểm: An toàn, dễ quản lý và thu hồi session, phù hợp với web app

Nhược điểm: Stateful (lưu trữ trên server), khó scale với distributed systems

Endpoint Login: https://material.playwrightvn.com/api/authentication/session_auth.php

Method: POST

Credentials: bba / demo_password

Response:

Click "Test Session Auth" to see response

Kiểm tra lại session

Endpoint: https://material.playwrightvn.com/api/authentication/session_test.php

Method: GET

Authentication type: COOKIE with returned header

SOAP (Simple Object Access Protocol) là một giao thức truyền thông dựa trên XML để trao đổi thông tin giữa các ứng dụng.

Cách hoạt động:

  • Client gửi SOAP request dạng XML đến server
  • Server xử lý và trả về SOAP response dạng XML
  • Sử dụng WSDL (Web Services Description Language) để mô tả service
  • Hỗ trợ nhiều transport protocols: HTTP, SMTP, TCP...

Cấu trúc SOAP Message:

  • Envelope: Phần bao ngoài, bắt buộc
  • Header: Chứa metadata (tùy chọn)
  • Body: Chứa dữ liệu chính (bắt buộc)
  • Fault: Thông tin lỗi (khi có lỗi)

Ưu điểm:

  • Bảo mật cao với WS-Security
  • Hỗ trợ ACID transactions
  • Độc lập với nền tảng và ngôn ngữ
  • Có chuẩn mực nghiêm ngặt

Nhược điểm:

  • Phức tạp, khó học
  • XML nặng hơn JSON
  • Performance thấp hơn REST
  • Khó debug và test

So sánh SOAP vs REST:

Tiêu chí SOAP REST
Kiểu Giao thức (Protocol) Kiến trúc (Architecture)
Format Chỉ XML JSON, XML, HTML...
Bảo mật WS-Security (rất mạnh) HTTPS, OAuth, JWT
Performance Chậm hơn Nhanh hơn
Sử dụng Banking, Finance, Enterprise Web, Mobile, Microservices

SOAP Server Endpoint: https://material.playwrightvn.com/api/authentication/soap/server.php

WSDL File: https://material.playwrightvn.com/api/authentication/soap/authentication.wsdl

Method: POST

Content-Type: text/xml; charset=utf-8

Valid Credentials:

  • Username: admin / Password: admin123
  • Username: user1 / Password: pass123
  • Username: testuser / Password: test456

Available Operations:

  1. login - Đăng nhập và nhận token
  2. register - Đăng ký tài khoản mới
  3. verifyToken - Xác thực token
  4. getUserInfo - Lấy thông tin user
  5. logout - Đăng xuất

1. Test SOAP Login

Response:

Click "Test SOAP Login" to see response

2. Test SOAP Register

Response:

Click "Test SOAP Register" to see response

3. Test Verify Token

Response:

Click "Test Verify Token" to see response

4. Test Get User Info

Response:

Click "Test Get User Info" to see response

5. Test Logout

Response:

Click "Test Logout" to see response

XML Request Examples

Login Request:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
               xmlns:tns="https://material.playwrightvn.com/api/authentication/soap/">
    <soap:Body>
        <tns:login>
            <tns:username>admin</tns:username>
            <tns:password>admin123</tns:password>
        </tns:login>
    </soap:Body>
</soap:Envelope>

Register Request:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
               xmlns:tns="https://material.playwrightvn.com/api/authentication/soap/">
    <soap:Body>
        <tns:register>
            <tns:username>newuser</tns:username>
            <tns:password>newpass123</tns:password>
            <tns:email>newuser@example.com</tns:email>
        </tns:register>
    </soap:Body>
</soap:Envelope>

Verify Token Request:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
               xmlns:tns="https://material.playwrightvn.com/api/authentication/soap/">
    <soap:Body>
        <tns:verifyToken>
            <tns:token>YOUR_TOKEN_HERE</tns:token>
        </tns:verifyToken>
    </soap:Body>
</soap:Envelope>

Tools for Testing SOAP

  • Postman: Import WSDL và test các operations
  • SoapUI: Tool chuyên dụng cho SOAP testing
  • cURL: Command line testing
  • PHP SoapClient: Test bằng code PHP
💡 Tips:
  • Sử dụng token từ login response cho các operations khác
  • Token có thời hạn 24 giờ
  • Kiểm tra WSDL file để xem chi tiết các operations
  • SOAP responses luôn ở dạng XML