Skip to content

Updated rusro auth - #21

Merged
kis1yi merged 2 commits into
Silkroad-Developer-Community:mainfrom
kis1yi:rusro
Jul 11, 2026
Merged

Updated rusro auth#21
kis1yi merged 2 commits into
Silkroad-Developer-Community:mainfrom
kis1yi:rusro

Conversation

@kis1yi

@kis1yi kis1yi commented Jul 11, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features
    • Added email-based OAuth authentication for 4game accounts.
    • Added support for verification-code login, including resending and resuming pending authorization.
    • Added automatic access-token reuse and refresh when valid credentials are available.
  • Bug Fixes
    • Improved authentication handling by validating account ownership and token validity before login.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@kis1yi, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 51 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 36651b95-1acb-4b49-b561-6c4b332c97d5

📥 Commits

Reviewing files that changed from the base of the PR and between 1f8841a and 0c1bef3.

📒 Files selected for processing (1)
  • Plugins/RSBot.General/Components/RuSroAuthService.cs
📝 Walkthrough

Walkthrough

RuSroAuthService now uses email-based 4game OAuth authentication with token reuse, refresh, email-code authorization, and persisted token and pending-flow state. Device identity handling and WebSocket login logging were also updated.

Changes

Email OAuth authentication

Layer / File(s) Summary
Token lifecycle and authentication entry point
Plugins/RSBot.General/Components/RuSroAuthService.cs
Auth() validates the selected email and obtains account-owned access tokens through cache reuse, refresh, or email authorization.
Email-code authorization flow
Plugins/RSBot.General/Components/RuSroAuthService.cs
The service initializes OAuth, resumes or resends verification codes, prompts for input, validates redirects, and exchanges authorization codes for tokens.
Token, pending-state, and device persistence
Plugins/RSBot.General/Components/RuSroAuthService.cs
Configuration stores token ownership and pending authorization data, while JWT validation, device identity generation, redirect parsing, and error extraction support the flow.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant RuSroAuthService
  participant 4gameAuth
  participant 4gameOAuth
  participant GlobalConfig
  User->>RuSroAuthService: Start authentication
  RuSroAuthService->>GlobalConfig: Read cached token state
  RuSroAuthService->>4gameOAuth: Refresh token or begin email authorization
  4gameAuth-->>RuSroAuthService: Return email-code authorization result
  RuSroAuthService->>4gameOAuth: Exchange authorization code
  4gameOAuth-->>RuSroAuthService: Return access and refresh tokens
  RuSroAuthService->>GlobalConfig: Persist token and authorization state
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change by indicating a RusSro authentication update.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
Plugins/RSBot.General/Components/RuSroAuthService.cs (1)

479-480: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Parse the round-trip timestamp with invariant culture.

codeRequestedAt is written with ToString("O") (ISO-8601 round-trip) but read back with the ambient-culture TryParse. Use invariant culture and round-trip styles so the value is parsed deterministically regardless of the host locale.

♻️ Suggested change
-        if (!DateTimeOffset.TryParse(requestedAt, out codeRequestedAt))
+        if (!DateTimeOffset.TryParse(
+                requestedAt,
+                CultureInfo.InvariantCulture,
+                DateTimeStyles.RoundtripKind,
+                out codeRequestedAt))
             codeRequestedAt = DateTimeOffset.MinValue;

Requires using System.Globalization;.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Plugins/RSBot.General/Components/RuSroAuthService.cs` around lines 479 - 480,
Update the requested timestamp parsing in the codeRequestedAt assignment to use
CultureInfo.InvariantCulture with DateTimeStyles.RoundtripKind, adding the
System.Globalization import required for these symbols. Preserve the existing
DateTimeOffset.MinValue fallback when parsing fails.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Plugins/RSBot.General/Components/RuSroAuthService.cs`:
- Around line 429-431: Update SaveTokens around GlobalConfig.Set for
RefreshTokenConfigKey so the long-lived refresh token is not stored in
plaintext; persist it through the existing encrypted/secure storage mechanism,
or omit persistence and retain only the access token and token owner settings.

---

Nitpick comments:
In `@Plugins/RSBot.General/Components/RuSroAuthService.cs`:
- Around line 479-480: Update the requested timestamp parsing in the
codeRequestedAt assignment to use CultureInfo.InvariantCulture with
DateTimeStyles.RoundtripKind, adding the System.Globalization import required
for these symbols. Preserve the existing DateTimeOffset.MinValue fallback when
parsing fails.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1a6d4cb8-30fb-4817-affc-895702a43b43

📥 Commits

Reviewing files that changed from the base of the PR and between a113e15 and 1f8841a.

📒 Files selected for processing (1)
  • Plugins/RSBot.General/Components/RuSroAuthService.cs

Comment on lines +429 to +431
GlobalConfig.Set(AccessTokenConfigKey, tokenResponse.AccessToken);
GlobalConfig.Set(RefreshTokenConfigKey, refreshToken);
GlobalConfig.Set(TokenOwnerConfigKey, email);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Inspect how GlobalConfig persists values (encryption vs plaintext)
fd -t f -i 'globalconfig' -x cat -n {}
fd -t f -i 'config.cs' Library -x sed -n '1,200p' {}

Repository: Silkroad-Developer-Community/OasisBot

Length of output: 19030


Persist the OAuth tokens with protection at rest
SaveTokens writes the access token and long-lived refresh token into GlobalConfig, and that config is serialized as plaintext. Store the refresh token in encrypted storage or avoid persisting it.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Plugins/RSBot.General/Components/RuSroAuthService.cs` around lines 429 - 431,
Update SaveTokens around GlobalConfig.Set for RefreshTokenConfigKey so the
long-lived refresh token is not stored in plaintext; persist it through the
existing encrypted/secure storage mechanism, or omit persistence and retain only
the access token and token owner settings.

@kis1yi
kis1yi merged commit 9259f53 into Silkroad-Developer-Community:main Jul 11, 2026
2 checks passed
@kis1yi
kis1yi deleted the rusro branch July 11, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant