Skip to content

Commit 0a86702

Browse files
authored
feat(github): authorize agent identities from Settings (#126474)
* feat(github): add device authorization lifecycle * fix(github): harden device authorization lifecycle * fix(github): refresh native tool display snapshot * fix(github): refresh config and UI baselines * refactor(github): break OAuth identity import cycle * test: make gateway retry deadline assertion scheduler-safe
1 parent 3aff572 commit 0a86702

77 files changed

Lines changed: 7776 additions & 618 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewayProtocol.kt‎

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,118 @@ data class ProjectsListResult(
175175
val observedProjects: List<ProjectsListResultObservedProjectsItem>? = null,
176176
)
177177

178+
@Serializable
179+
data class GitHubIdentityFacts(
180+
val source: String,
181+
val credentialKind: String,
182+
val credentialState: String,
183+
val account: JsonElement,
184+
val gitAuthor: GitHubIdentityFactsGitAuthor,
185+
val evidence: String,
186+
val accessExpiresAtMs: JsonElement,
187+
val refreshState: String,
188+
val oauthScopes: List<String>,
189+
val repositoryGrants: String = "unknown",
190+
)
191+
192+
@Serializable
193+
data class GitHubSelectedIdentity(
194+
val scope: String,
195+
val configured: Boolean,
196+
val identity: JsonElement,
197+
)
198+
199+
@Serializable
200+
data class ToolsGitHubStatusParams(
201+
val agentId: String,
202+
val selectedScope: String,
203+
)
204+
205+
@Serializable
206+
data class ToolsGitHubStatusResult(
207+
val agentId: String,
208+
val selectedScope: String,
209+
val selected: GitHubSelectedIdentity,
210+
val effective: GitHubIdentityFacts,
211+
)
212+
213+
@Serializable
214+
data class ToolsGitHubAuthorizeStartParams(
215+
val scope: String,
216+
val agentId: String,
217+
)
218+
219+
@Serializable
220+
data class ToolsGitHubAuthorizeStartResult(
221+
val requestId: String,
222+
val userCode: String,
223+
val verificationUri: String = "https://github.com/login/device",
224+
val expiresInMs: Long,
225+
val pollAfterMs: Long,
226+
)
227+
228+
@Serializable
229+
data class ToolsGitHubAuthorizePollParams(
230+
val requestId: String,
231+
)
232+
233+
@SerialName("pending")
234+
@Serializable
235+
data class ToolsGitHubAuthorizePendingResult(
236+
val retryAfterMs: Long,
237+
) : ToolsGitHubAuthorizePollResult
238+
239+
@SerialName("slow_down")
240+
@Serializable
241+
data class ToolsGitHubAuthorizeSlowDownResult(
242+
val retryAfterMs: Long,
243+
) : ToolsGitHubAuthorizePollResult
244+
245+
@SerialName("access_denied")
246+
@Serializable
247+
data object ToolsGitHubAuthorizeAccessDeniedResult : ToolsGitHubAuthorizePollResult
248+
249+
@SerialName("expired")
250+
@Serializable
251+
data object ToolsGitHubAuthorizeExpiredResult : ToolsGitHubAuthorizePollResult
252+
253+
@SerialName("incorrect_device_code")
254+
@Serializable
255+
data object ToolsGitHubAuthorizeIncorrectDeviceCodeResult : ToolsGitHubAuthorizePollResult
256+
257+
@SerialName("network_error")
258+
@Serializable
259+
data class ToolsGitHubAuthorizeNetworkErrorResult(
260+
val retryAfterMs: Long,
261+
) : ToolsGitHubAuthorizePollResult
262+
263+
@SerialName("failed")
264+
@Serializable
265+
data class ToolsGitHubAuthorizeFailedResult(
266+
val reason: String,
267+
) : ToolsGitHubAuthorizePollResult
268+
269+
@SerialName("success")
270+
@Serializable
271+
data class ToolsGitHubAuthorizeSuccessResult(
272+
val githubStatus: ToolsGitHubStatusResult,
273+
) : ToolsGitHubAuthorizePollResult
274+
275+
@OptIn(ExperimentalSerializationApi::class)
276+
@Serializable
277+
@JsonClassDiscriminator("status")
278+
sealed interface ToolsGitHubAuthorizePollResult
279+
280+
@Serializable
281+
data class ToolsGitHubAuthorizeCancelParams(
282+
val requestId: String,
283+
)
284+
285+
@Serializable
286+
data class ToolsGitHubAuthorizeCancelResult(
287+
val cancelled: Boolean,
288+
)
289+
178290
@SerialName("requested")
179291
@Serializable
180292
data class SessionGitHubPublicationRequested(
@@ -243,6 +355,12 @@ data class ProjectsListResultObservedProjectsItem(
243355
val lastUsedAt: Double,
244356
)
245357

358+
@Serializable
359+
data class GitHubIdentityFactsGitAuthor(
360+
val name: JsonElement,
361+
val email: JsonElement,
362+
)
363+
246364
@Serializable
247365
data class ProjectsListResultObservedProjectsItemCheckoutsItem(
248366
val runnerId: String,
@@ -631,6 +749,9 @@ enum class GatewayMethod(
631749
ProgressCardPut("progressCard.put"),
632750
ToolsGithubStatus("tools.github.status"),
633751
ToolsGithubConfigure("tools.github.configure"),
752+
ToolsGithubAuthorizeStart("tools.github.authorize.start"),
753+
ToolsGithubAuthorizePoll("tools.github.authorize.poll"),
754+
ToolsGithubAuthorizeCancel("tools.github.authorize.cancel"),
634755
SessionsGithubPublish("sessions.github.publish"),
635756
DiagnosticsLanes("diagnostics.lanes"),
636757
}

‎apps/android/app/src/test/java/ai/openclaw/app/gateway/GatewayProtocolGeneratedTest.kt‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,43 @@ class GatewayProtocolGeneratedTest {
9696
)
9797
}
9898
}
99+
100+
@Test
101+
fun githubDeviceAuthorizationResultsRoundTripAsATypedUnion() {
102+
val cases =
103+
listOf(
104+
"""{"status":"pending","retryAfterMs":5000}""" to
105+
ToolsGitHubAuthorizePendingResult::class,
106+
"""{"status":"slow_down","retryAfterMs":10000}""" to
107+
ToolsGitHubAuthorizeSlowDownResult::class,
108+
"""{"status":"access_denied"}""" to ToolsGitHubAuthorizeAccessDeniedResult::class,
109+
"""{"status":"expired"}""" to ToolsGitHubAuthorizeExpiredResult::class,
110+
"""{"status":"incorrect_device_code"}""" to
111+
ToolsGitHubAuthorizeIncorrectDeviceCodeResult::class,
112+
"""{"status":"network_error","retryAfterMs":5000}""" to
113+
ToolsGitHubAuthorizeNetworkErrorResult::class,
114+
"""{"status":"failed","reason":"identity_changed"}""" to
115+
ToolsGitHubAuthorizeFailedResult::class,
116+
"""{"status":"success","githubStatus":{"agentId":"main","selectedScope":"system","selected":{"scope":"system","configured":true,"identity":{"source":"system-configured","credentialKind":"managed-oauth","credentialState":"available","account":{"login":"octocat"},"gitAuthor":{"name":"octocat","email":"[email protected]"},"evidence":"github-api","accessExpiresAtMs":1800000000000,"refreshState":"available","oauthScopes":["repo"],"repositoryGrants":"unknown"}},"effective":{"source":"system-configured","credentialKind":"managed-oauth","credentialState":"available","account":{"login":"octocat"},"gitAuthor":{"name":"octocat","email":"[email protected]"},"evidence":"github-api","accessExpiresAtMs":1800000000000,"refreshState":"available","oauthScopes":["repo"],"repositoryGrants":"unknown"}}}""" to
117+
ToolsGitHubAuthorizeSuccessResult::class,
118+
)
119+
120+
for ((payload, expectedType) in cases) {
121+
val decoded = json.decodeFromString(ToolsGitHubAuthorizePollResult.serializer(), payload)
122+
assertEquals(expectedType, decoded::class)
123+
val encoded =
124+
json
125+
.encodeToJsonElement(ToolsGitHubAuthorizePollResult.serializer(), decoded)
126+
.jsonObject
127+
assertEquals(
128+
json
129+
.parseToJsonElement(payload)
130+
.jsonObject
131+
.getValue("status")
132+
.jsonPrimitive
133+
.content,
134+
encoded.getValue("status").jsonPrimitive.content,
135+
)
136+
}
137+
}
99138
}

‎apps/shared/OpenClawKit/Sources/OpenClawKit/Resources/tool-display.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,11 @@
532532
"title"
533533
]
534534
},
535+
"github_identity_status": {
536+
"emoji": "🔐",
537+
"title": "GitHub Identity Status",
538+
"detailKeys": []
539+
},
535540
"sessions": {
536541
"emoji": "🗂️",
537542
"title": "Session Settings",

0 commit comments

Comments
 (0)