Skip to content

Commit eee9456

Browse files
Release v11.4.5
Origin-SHA: 827450af53927bfec7e89cb8b7f39d276e144a93 Co-authored-by: Ryan Ghods <ryan@ryanio.com>
1 parent b1da82e commit eee9456

5 files changed

Lines changed: 30 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# @opensea/sdk
22

3+
## 11.4.5
4+
5+
### Patch Changes
6+
7+
- d10626b: Add an `opensea whoami` command that displays the current wallet identity,
8+
scope source, and expiry, with unverified JWT diagnostics available through an
9+
explicit flag. Expose whether OAuth scopes came from the authorization-server
10+
response or a JWT fallback.
11+
312
## 11.4.4
413

514
### Patch Changes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@opensea/sdk",
3-
"version": "11.4.4",
3+
"version": "11.4.5",
44
"description": "TypeScript SDK for the OpenSea marketplace helps developers build new experiences using NFTs, tokens, and our marketplace data",
55
"license": "MIT",
66
"author": "OpenSea Developers",

src/auth/oauth-types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export interface OAuthToken {
3131
expiresAt: Date
3232
/** Scopes granted to this token. */
3333
scopes: string[]
34+
/** Source of the scopes exposed to consumers. */
35+
scopeSource: "authorization_server" | "jwt_claim"
3436
}
3537

3638
/**

src/auth/oauth.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,19 @@ export function extractOpenSeaScopes(accessToken: string): string[] {
367367
return []
368368
}
369369

370-
function tokenOpenSeaScopes(response: OAuthTokenResponse): string[] {
370+
function tokenOpenSeaScopes(response: OAuthTokenResponse): {
371+
scopes: string[]
372+
scopeSource: OAuthToken["scopeSource"]
373+
} {
371374
const responseScopes = response.scope
372375
? canonicalOpenSeaScopes(response.scope.split(/\s+/).filter(Boolean))
373376
: []
374377
return responseScopes.length > 0
375-
? responseScopes
376-
: extractOpenSeaScopes(response.access_token)
378+
? { scopes: responseScopes, scopeSource: "authorization_server" }
379+
: {
380+
scopes: extractOpenSeaScopes(response.access_token),
381+
scopeSource: "jwt_claim",
382+
}
377383
}
378384

379385
function toOAuthToken(
@@ -389,12 +395,14 @@ function toOAuthToken(
389395
if (!refreshToken) {
390396
throw new Error("OAuth token response is missing a refresh token")
391397
}
398+
const { scopes, scopeSource } = tokenOpenSeaScopes(response)
392399
return {
393400
accessToken: response.access_token,
394401
refreshToken,
395402
idToken: response.id_token,
396403
expiresAt: new Date(Date.now() + expiresIn * 1000),
397-
scopes: tokenOpenSeaScopes(response),
404+
scopes,
405+
scopeSource,
398406
}
399407
}
400408

test/auth/oauth.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ describe("OpenSeaOAuth", () => {
171171
expect(token.accessToken).toBe("at")
172172
expect(token.refreshToken).toBe("rt")
173173
expect(token.scopes).toEqual(["read:eligibility", "write:orders"])
174+
expect(token.scopeSource).toBe("authorization_server")
174175
expect(token.expiresAt.getTime()).toBeGreaterThan(Date.now())
175176
})
176177

@@ -237,6 +238,7 @@ describe("OpenSeaOAuth", () => {
237238
})
238239

239240
expect(token.scopes).toEqual(["read:eligibility", "write:orders"])
241+
expect(token.scopeSource).toBe("jwt_claim")
240242
})
241243

242244
test("reads array OpenSea scope claims in canonical API order", async () => {
@@ -262,6 +264,7 @@ describe("OpenSeaOAuth", () => {
262264
})
263265

264266
expect(token.scopes).toEqual(["read:favorites", "write:favorites"])
267+
expect(token.scopeSource).toBe("jwt_claim")
265268
})
266269

267270
test("filters token response scopes through the OpenAPI catalog", async () => {
@@ -286,6 +289,7 @@ describe("OpenSeaOAuth", () => {
286289
})
287290

288291
expect(token.scopes).toEqual(["read:eligibility"])
292+
expect(token.scopeSource).toBe("authorization_server")
289293
})
290294

291295
test.each([
@@ -315,6 +319,7 @@ describe("OpenSeaOAuth", () => {
315319
})
316320

317321
expect(token.scopes).toEqual([])
322+
expect(token.scopeSource).toBe("jwt_claim")
318323
})
319324

320325
test("refresh uses the refresh_token grant", async () => {
@@ -337,6 +342,7 @@ describe("OpenSeaOAuth", () => {
337342
expect(token.accessToken).toBe("at2")
338343
expect(token.refreshToken).toBe("rt2")
339344
expect(token.scopes).toEqual([])
345+
expect(token.scopeSource).toBe("jwt_claim")
340346
})
341347

342348
test("refresh retains the previous token when rotation omits one", async () => {

0 commit comments

Comments
 (0)