fix: correct bitFlyer API authentication bugs#20
Merged
Conversation
- fix(auth/signer): use Unix seconds (not milliseconds) for ACCESS-TIMESTAMP bitFlyer requires the timestamp in Unix seconds; UnixMilli() caused 403 errors on all authenticated HTTP REST API calls. - fix(auth/signer): include query string in signed message via RequestURI() Using URL.Path excluded query parameters from the signature, which would produce invalid signatures for private endpoints that accept query params (e.g. /v1/me/getpositions?product_code=FX_BTC_JPY). - fix(websocket): use nonce (not apiKey) when computing WebSocket auth signature bitFlyer WebSocket auth requires HMAC-SHA256(secret, timestamp+nonce). The nonce sent in the params must match the value used to compute the signature. - refactor: remove duplicate client/http/auth package The package only re-defined APICredentials already in client/auth, causing potential type confusion for users. client/auth.APICredentials is canonical. - test: add query-param signature coverage and verify seconds-based timestamp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug Fixes
Bug 1: ACCESS-TIMESTAMP was in milliseconds (Primary cause of 403 Forbidden on HTTP REST)
client/auth/signer.gotime.Now().UnixMilli()totime.Now().Unix().Bug 2: Query parameters were excluded from the signature target
client/auth/signer.goreq.URL.Pathwithreq.URL.RequestURI().URL.Pathcaused signature mismatches on endpoints like/v1/me/getpositions?product_code=FX_BTC_JPY.Bug 3: WebSocket authentication signature used apiKey instead of nonce
client/websocket/client.go(Auth()function)noncefor signature generation.HMAC-SHA256(secret, timestamp + nonce). The previous code incorrectly included the API Key in the payload, leading to authentication failures.Verification Items