Swiftpack.co - kevinzhow/baiducloudsigner-swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by kevinzhow.
kevinzhow/baiducloudsigner-swift 0.0.3
A simple request signer for baidu cloud
⭐️ 1
🕓 4 weeks ago
iOS macOS
.package(url: "https://github.com/kevinzhow/baiducloudsigner-swift.git", from: "0.0.3")

BaiduCloudSigner

对应 V1 签名方式

Installation

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/kevinzhow/baiducloudsigner-swift.git", .upToNextMajor(from: "0.0.1"))
]

Usage

OCR example, please ref to BaiduCloudSignerTests for full code.

Sign Request

let signer = BaiduCloudSigner(ak: "", sk: "")

let url = URL(string: "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic")!

var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField:"Content-Type")
request.httpBody = "image=\(imageFileBase64)&language_type=JAP&paragraph=true&detect_direction=true".data(using: .utf8)!

let signedRequest = signer.sign(request: request)

let session = URLSession.shared

let (data, _) = try await session.data(for: signedRequest)

Get Signed Authorization Header

This is the underlying implements of Sign Request

let method = "POST"

let url = URL(string: "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic")!

var headers = ["Content-Type": "application/x-www-form-urlencoded"]

let signer = BaiduCloudSigner(ak: "", sk: "")

let authHeader = signer.sign(method: method, url: url, headers: headers)
headers["Authorization"] = authHeader

GitHub

link
Stars: 1
Last commit: 4 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Dependencies

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics