fix: add step-by-step logs in exchangeCode to pinpoint crash location
The log stops after tenant_token fetch but before the OAuth token exchange HTTP request. Added per-line logging to find exactly where it dies: URL construction, body encoding, or the send() call. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
12e22da9b3
commit
f61f8332b8
|
|
@ -42,19 +42,20 @@ final class FeishuAuthService {
|
||||||
}
|
}
|
||||||
|
|
||||||
func exchangeCode(_ code: String) async throws -> OAuthTokenData {
|
func exchangeCode(_ code: String) async throws -> OAuthTokenData {
|
||||||
BuggerLog.info("Exchanging auth code (len=\(code.count)) for user token...")
|
BuggerLog.info("exchangeCode: start, code len=\(code.count)")
|
||||||
let tenantToken = try await tenantAccessToken()
|
let tenantToken = try await tenantAccessToken()
|
||||||
|
BuggerLog.info("exchangeCode: got tenant token, building request...")
|
||||||
let url = URL(string: "\(baseURL)/authen/v1/oidc/access_token")!
|
let url = URL(string: "\(baseURL)/authen/v1/oidc/access_token")!
|
||||||
var request = URLRequest(url: url)
|
var request = URLRequest(url: url)
|
||||||
request.httpMethod = "POST"
|
request.httpMethod = "POST"
|
||||||
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
|
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
|
||||||
request.setValue("Bearer \(tenantToken)", forHTTPHeaderField: "Authorization")
|
request.setValue("Bearer \(tenantToken)", forHTTPHeaderField: "Authorization")
|
||||||
request.httpBody = try JSONEncoder().encode([
|
BuggerLog.info("exchangeCode: encoding body...")
|
||||||
"grant_type": "authorization_code",
|
let body: [String: String] = ["grant_type": "authorization_code", "code": code]
|
||||||
"code": code,
|
request.httpBody = try JSONEncoder().encode(body)
|
||||||
] as [String: String])
|
BuggerLog.info("exchangeCode: body encoded (\(request.httpBody?.count ?? 0)B), sending...")
|
||||||
let tokenData: OAuthTokenData = try await send(request)
|
let tokenData: OAuthTokenData = try await send(request)
|
||||||
BuggerLog.info("Got token: access=\(tokenData.accessToken.prefix(8))..., refresh=\(tokenData.refreshToken?.prefix(8) ?? "nil")..., expires=\(tokenData.expiresIn)")
|
BuggerLog.info("exchangeCode: got token access=\(tokenData.accessToken.prefix(8))... refresh=\(tokenData.refreshToken?.prefix(8) ?? "nil")...")
|
||||||
return tokenData
|
return tokenData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue