Use camelCase names for the OAuth helpers

Eleven functions in oauth.zig, chatgpt_oauth.zig, and grok_oauth.zig
used snake_case names, against the repository's camelCase rule for
functions. They and their callers are renamed, and nothing else
changes.
This commit is contained in:
Pranit committed 2026-10-22 12:44:20 -04:00
1 parent fd726cc0d3
commit d072810a68
6 files changed
+46 -46

No files matched your search

+8 -8
View File
@@ -410,24 +410,24 @@ fn refreshSession(
error.InvalidChatGptOAuthResponse,
=> {
debug_trace.logf("auth", "retiring terminal Codex session reason={s}", .{@errorName(err)});
try retire_refresh_session(mutation);
try retireRefreshSession(mutation);
return error.CredentialRefreshRejected;
},
else => return err,
};
defer token.deinit(alloc);
var replacement = refresh_replacement(alloc, &token, session.*) catch |err| {
var replacement = refreshReplacement(alloc, &token, session.*) catch |err| {
if (err == error.OutOfMemory) return err;
debug_trace.logf("auth", "retiring unusable Codex refresh reason={s}", .{@errorName(err)});
try retire_refresh_session(mutation);
try retireRefreshSession(mutation);
if (err == error.ChatGptAccountChanged) return err;
return error.CredentialRefreshRejected;
};
errdefer replacement.deinit(alloc);
mutation.save(alloc, replacement) catch |err| {
debug_trace.logf("auth", "retiring Codex session after refresh save failed err={s}", .{@errorName(err)});
retire_refresh_session(mutation) catch |cleanup_err| {
retireRefreshSession(mutation) catch |cleanup_err| {
debug_trace.logf("auth", "Codex session retirement failed err={s}", .{@errorName(cleanup_err)});
};
return error.CredentialRefreshPersistenceUncertain;
@@ -440,7 +440,7 @@ fn refreshSession(
replacement.account_id = &.{};
}
fn refresh_replacement(
fn refreshReplacement(
alloc: Allocator,
token: *RefreshTokenResponse,
current: chatgpt_session.Session,
@@ -472,7 +472,7 @@ fn refresh_replacement(
return replacement;
}
fn retire_refresh_session(mutation: *chatgpt_session.Mutation) !void {
fn retireRefreshSession(mutation: *chatgpt_session.Mutation) !void {
const outcome = mutation.delete() catch return error.CredentialRefreshPersistenceUncertain;
if (outcome == .deleted_not_durable) return error.CredentialRefreshPersistenceUncertain;
}
@@ -504,7 +504,7 @@ fn requestRefreshToken(
defer response.deinit(alloc);
if (response.disposition != .accepted) {
debug_trace.logf("auth", "Codex refresh request rejected", .{});
if (chat_gpt_refresh_requires_sign_in(response.body)) {
if (chatGptRefreshRequiresSignIn(response.body)) {
return error.CredentialRefreshRejected;
}
return error.ChatGptOAuthRequestFailed;
@@ -533,7 +533,7 @@ fn requestRefreshToken(
};
}
fn chat_gpt_refresh_requires_sign_in(body: []const u8) bool {
fn chatGptRefreshRequiresSignIn(body: []const u8) bool {
const terminal_codes = [_][]const u8{
"\"refresh_token_expired\"",
"\"refresh_token_reused\"",
+1 -1
View File
@@ -815,7 +815,7 @@ pub fn refreshFxSession(
try retire_fx_session(alloc, mutation);
return error.NoRefreshToken;
};
const expires_at_ms = oauth.expiry_timestamp_ms(
const expires_at_ms = oauth.expiryTimestampMs(
io_mod.milliTimestamp(),
refreshed.expires_in,
) catch |err| {
+6 -6
View File
@@ -514,24 +514,24 @@ fn refreshSession(
error.InvalidGrokOAuthResponse,
=> {
debug_trace.logf("auth", "retiring terminal Grok session reason={s}", .{@errorName(err)});
try retire_refresh_session(mutation);
try retireRefreshSession(mutation);
return error.CredentialRefreshRejected;
},
else => return err,
};
defer token.deinit(alloc);
var replacement = refresh_replacement(alloc, transport, &token, session.*) catch |err| {
var replacement = refreshReplacement(alloc, transport, &token, session.*) catch |err| {
if (err == error.OutOfMemory) return err;
debug_trace.logf("auth", "retiring unusable Grok refresh reason={s}", .{@errorName(err)});
try retire_refresh_session(mutation);
try retireRefreshSession(mutation);
if (err == error.GrokAccountChanged) return err;
return error.CredentialRefreshRejected;
};
errdefer replacement.deinit(alloc);
mutation.save(alloc, replacement) catch |err| {
debug_trace.logf("auth", "retiring Grok session after refresh save failed err={s}", .{@errorName(err)});
retire_refresh_session(mutation) catch |cleanup_err| {
retireRefreshSession(mutation) catch |cleanup_err| {
debug_trace.logf("auth", "Grok session retirement failed err={s}", .{@errorName(cleanup_err)});
};
return error.CredentialRefreshPersistenceUncertain;
@@ -544,7 +544,7 @@ fn refreshSession(
replacement.account_id = &.{};
}
fn refresh_replacement(
fn refreshReplacement(
alloc: Allocator,
transport: oauth_transport.Provider,
token: *RefreshTokenResponse,
@@ -576,7 +576,7 @@ fn refresh_replacement(
return replacement;
}
fn retire_refresh_session(mutation: *grok_session.Mutation) !void {
fn retireRefreshSession(mutation: *grok_session.Mutation) !void {
const outcome = mutation.delete() catch return error.CredentialRefreshPersistenceUncertain;
if (outcome == .deleted_not_durable) return error.CredentialRefreshPersistenceUncertain;
}
+2 -2
View File
@@ -749,7 +749,7 @@ fn take_login_session(
now_ms: i64,
) !oauth_session.Session {
const refresh_token = token.refresh_token orelse return LoginError.NoRefreshToken;
const expires_at_ms = try oauth.expiry_timestamp_ms(now_ms, token.expires_in);
const expires_at_ms = try oauth.expiryTimestampMs(now_ms, token.expires_in);
const owned_issuer = try alloc.dupe(u8, issuer_url);
errdefer alloc.free(owned_issuer);
const owned_client_id = try alloc.dupe(u8, client_id);
@@ -948,7 +948,7 @@ const LoginPollState = struct {
fn init(deps: LoginPollDeps, device: oauth.DeviceAuthorization) !LoginPollState {
const now_ms = deps.now_ms(deps.ctx);
return .{
.expires_at_ms = try oauth.expiry_timestamp_ms(now_ms, device.expires_in),
.expires_at_ms = try oauth.expiryTimestampMs(now_ms, device.expires_in),
.interval_ms = try poll_interval_ms(device.interval),
.next_poll_at_ms = now_ms,
};
+21 -21
View File
@@ -130,7 +130,7 @@ pub const TokenTypeHint = enum {
refresh_token,
};
pub fn expiry_timestamp_ms(now_ms: i64, expires_in_seconds: i64) OAuthError!i64 {
pub fn expiryTimestampMs(now_ms: i64, expires_in_seconds: i64) OAuthError!i64 {
if (expires_in_seconds <= 0) return OAuthError.InvalidOAuthResponse;
const duration_ms = std.math.mul(i64, expires_in_seconds, std.time.ms_per_s) catch
return OAuthError.InvalidOAuthResponse;
@@ -500,7 +500,7 @@ pub fn queryValueNonEmptyAlloc(
}
pub fn percentDecodeAlloc(alloc: Allocator, value: []const u8) QueryError![]u8 {
return percent_decode_alloc_detailed(alloc, value) catch |err| switch (err) {
return percentDecodeAllocDetailed(alloc, value) catch |err| switch (err) {
error.OutOfMemory => error.OutOfMemory,
else => error.InvalidPercentEncoding,
};
@@ -511,7 +511,7 @@ const PercentDecodeDetailedError = std.mem.Allocator.Error || error{
InvalidPercentDigit,
};
fn percent_decode_alloc_detailed(alloc: Allocator, value: []const u8) PercentDecodeDetailedError![]u8 {
fn percentDecodeAllocDetailed(alloc: Allocator, value: []const u8) PercentDecodeDetailedError![]u8 {
var out = try alloc.alloc(u8, value.len);
errdefer alloc.free(out);
var read_index: usize = 0;
@@ -558,14 +558,14 @@ pub const FormCallbackContext = struct {
consumed: bool = false,
};
pub fn parse_form_callback(
pub fn parseFormCallback(
raw: ?*anyopaque,
alloc: Allocator,
body: []const u8,
) browser_callback.ParseResult(FormCallback) {
const context: *FormCallbackContext = @ptrCast(@alignCast(raw.?));
if (context.consumed) return .unrelated;
const callback = parse_form_callback_body(alloc, body, context) catch |err| {
const callback = parseFormCallbackBody(alloc, body, context) catch |err| {
if (err == error.OAuthFormStateMismatch) return .unrelated;
return .{ .failed = err };
};
@@ -573,12 +573,12 @@ pub fn parse_form_callback(
return .{ .accepted = callback };
}
fn decode_form_callback_component(
fn decodeFormCallbackComponent(
alloc: Allocator,
value: []const u8,
context: *const FormCallbackContext,
) ![]u8 {
const decoded = percent_decode_alloc_detailed(alloc, value) catch |err| switch (err) {
const decoded = percentDecodeAllocDetailed(alloc, value) catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
error.TruncatedPercentEncoding => return if (context.require_visible_ascii)
context.invalid_error
@@ -596,7 +596,7 @@ fn decode_form_callback_component(
return decoded;
}
fn parse_form_callback_body(
fn parseFormCallbackBody(
alloc: Allocator,
body: []const u8,
context: *const FormCallbackContext,
@@ -606,7 +606,7 @@ fn parse_form_callback_body(
var fields = std.mem.splitScalar(u8, body, '&');
while (fields.next()) |field| {
const equals = std.mem.findScalar(u8, field, '=') orelse return context.invalid_error;
const name = try decode_form_callback_component(alloc, field[0..equals], context);
const name = try decodeFormCallbackComponent(alloc, field[0..equals], context);
defer alloc.free(name);
const index: usize = if (std.mem.eql(u8, name, "state"))
0
@@ -619,7 +619,7 @@ fn parse_form_callback_body(
else
return context.invalid_error;
if (values[index] != null) return context.invalid_error;
const value = try decode_form_callback_component(alloc, field[equals + 1 ..], context);
const value = try decodeFormCallbackComponent(alloc, field[equals + 1 ..], context);
values[index] = value;
if (value.len == 0 or value.len > context.max_value_bytes) return context.invalid_error;
if (index == 1 and value.len > context.code_max_bytes) return context.invalid_error;
@@ -744,7 +744,7 @@ test "browser token parsing and transfer clean up allocation failures" {
);
}
fn check_metadata_allocation_failures(alloc: Allocator) !void {
fn checkMetadataAllocationFailures(alloc: Allocator) !void {
var metadata = try parseMetadata(
alloc,
"{\"issuer\":\"https://vercel.com\",\"device_authorization_endpoint\":\"https://vercel.com/device\",\"token_endpoint\":\"https://vercel.com/token\",\"revocation_endpoint\":\"https://vercel.com/revoke\"}",
@@ -752,7 +752,7 @@ fn check_metadata_allocation_failures(alloc: Allocator) !void {
defer metadata.deinit(alloc);
}
fn check_device_authorization_allocation_failures(alloc: Allocator) !void {
fn checkDeviceAuthorizationAllocationFailures(alloc: Allocator) !void {
var device = try parseDeviceAuthorization(
alloc,
"{\"device_code\":\"device\",\"user_code\":\"user\",\"verification_uri\":\"https://vercel.com/verify\",\"verification_uri_complete\":\"https://vercel.com/verify?code=user\",\"expires_in\":600,\"interval\":5}",
@@ -760,7 +760,7 @@ fn check_device_authorization_allocation_failures(alloc: Allocator) !void {
defer device.deinit(alloc);
}
fn check_token_set_allocation_failures(alloc: Allocator) !void {
fn checkTokenSetAllocationFailures(alloc: Allocator) !void {
var token = try parseTokenSet(
alloc,
"{\"access_token\":\"access\",\"refresh_token\":\"refresh\",\"expires_in\":3600,\"scope\":\"openid offline_access\",\"token_type\":\"Bearer\"}",
@@ -931,17 +931,17 @@ test "oauth parses token set" {
}
test "oauth parsers clean up allocation failures" {
try std.testing.checkAllAllocationFailures(testing_allocator.no_resize, check_metadata_allocation_failures, .{});
try std.testing.checkAllAllocationFailures(testing_allocator.no_resize, check_device_authorization_allocation_failures, .{});
try std.testing.checkAllAllocationFailures(testing_allocator.no_resize, check_token_set_allocation_failures, .{});
try std.testing.checkAllAllocationFailures(testing_allocator.no_resize, checkMetadataAllocationFailures, .{});
try std.testing.checkAllAllocationFailures(testing_allocator.no_resize, checkDeviceAuthorizationAllocationFailures, .{});
try std.testing.checkAllAllocationFailures(testing_allocator.no_resize, checkTokenSetAllocationFailures, .{});
}
test "oauth expiry timestamps reject invalid durations" {
try std.testing.expectEqual(@as(i64, 11_000), try expiry_timestamp_ms(1_000, 10));
try std.testing.expectError(OAuthError.InvalidOAuthResponse, expiry_timestamp_ms(1_000, 0));
try std.testing.expectError(OAuthError.InvalidOAuthResponse, expiry_timestamp_ms(1_000, -1));
try std.testing.expectError(OAuthError.InvalidOAuthResponse, expiry_timestamp_ms(1_000, std.math.maxInt(i64)));
try std.testing.expectError(OAuthError.InvalidOAuthResponse, expiry_timestamp_ms(std.math.maxInt(i64), 1));
try std.testing.expectEqual(@as(i64, 11_000), try expiryTimestampMs(1_000, 10));
try std.testing.expectError(OAuthError.InvalidOAuthResponse, expiryTimestampMs(1_000, 0));
try std.testing.expectError(OAuthError.InvalidOAuthResponse, expiryTimestampMs(1_000, -1));
try std.testing.expectError(OAuthError.InvalidOAuthResponse, expiryTimestampMs(1_000, std.math.maxInt(i64)));
try std.testing.expectError(OAuthError.InvalidOAuthResponse, expiryTimestampMs(std.math.maxInt(i64), 1));
}
test "oauth parsers reject non-object JSON" {
+8 -8
View File
@@ -102,7 +102,7 @@ pub fn run(alloc: Allocator, action: Action, transport: transport_mod.Provider,
var cancelled: std.atomic.Value(bool) = .init(false);
while (accepted == null) {
if (deadline.durationFromNow(io.getIo()).raw.nanoseconds <= 0) return error.SlackAuthorizationExpired;
accepted = try browser.await_form(oauth.FormCallback, oauth.parse_form_callback, alloc, &listener, &context, &cancelled, null, origin);
accepted = try browser.await_form(oauth.FormCallback, oauth.parseFormCallback, alloc, &listener, &context, &cancelled, null, origin);
}
if (deadline.durationFromNow(io.getIo()).raw.nanoseconds <= 0) return error.SlackAuthorizationExpired;
if (accepted.?.callback.denied) return error.SlackAuthorizationDenied;
@@ -279,11 +279,11 @@ test "Slack callback consumes matching state once and rejects ambiguous fields"
.require_visible_ascii = true,
.max_value_bytes = 8192,
};
try std.testing.expect(oauth.parse_form_callback(&context, alloc, "state=wrong&code=code") == .unrelated);
try std.testing.expect(oauth.parseFormCallback(&context, alloc, "state=wrong&code=code") == .unrelated);
try std.testing.expect(!context.consumed);
const accepted = oauth.parse_form_callback(&context, alloc, "state=expected&code=code%2Bvalue");
const accepted = oauth.parseFormCallback(&context, alloc, "state=expected&code=code%2Bvalue");
try std.testing.expectEqualStrings("code+value", accepted.accepted.code.?);
try std.testing.expect(oauth.parse_form_callback(&context, alloc, "state=expected&code=code") == .unrelated);
try std.testing.expect(oauth.parseFormCallback(&context, alloc, "state=expected&code=code") == .unrelated);
for ([_][]const u8{
"state=expected&state=expected&code=code",
"state=expected&code=code&error=denied",
@@ -295,7 +295,7 @@ test "Slack callback consumes matching state once and rejects ambiguous fields"
.require_visible_ascii = true,
.max_value_bytes = 8192,
};
const invalid = oauth.parse_form_callback(&invalid_context, alloc, body);
const invalid = oauth.parseFormCallback(&invalid_context, alloc, body);
try std.testing.expect(invalid == .failed);
try std.testing.expectEqual(error.InvalidSlackCallback, invalid.failed);
}
@@ -305,7 +305,7 @@ test "Slack callback consumes matching state once and rejects ambiguous fields"
.require_visible_ascii = true,
.max_value_bytes = 8192,
};
try std.testing.expect(oauth.parse_form_callback(&missing_state_context, alloc, "code=code") == .unrelated);
try std.testing.expect(oauth.parseFormCallback(&missing_state_context, alloc, "code=code") == .unrelated);
for ([_]struct { body: []const u8, expected: anyerror }{
.{ .body = "state=expected&code=%zz", .expected = error.InvalidCharacter },
.{ .body = "state=expected&code=%", .expected = error.InvalidSlackCallback },
@@ -316,7 +316,7 @@ test "Slack callback consumes matching state once and rejects ambiguous fields"
.require_visible_ascii = true,
.max_value_bytes = 8192,
};
const malformed = oauth.parse_form_callback(&malformed_context, alloc, scenario.body);
const malformed = oauth.parseFormCallback(&malformed_context, alloc, scenario.body);
try std.testing.expectEqual(scenario.expected, malformed.failed);
}
var denied_context = oauth.FormCallbackContext{
@@ -325,7 +325,7 @@ test "Slack callback consumes matching state once and rejects ambiguous fields"
.require_visible_ascii = true,
.max_value_bytes = 8192,
};
const denied = oauth.parse_form_callback(&denied_context, alloc, "state=expected&error=access_denied");
const denied = oauth.parseFormCallback(&denied_context, alloc, "state=expected&error=access_denied");
try std.testing.expect(denied.accepted.denied);
try std.testing.expect(valid_id("UBOT", "UW"));
try std.testing.expect(valid_id("WBOT", "UW"));