-
Notifications
You must be signed in to change notification settings - Fork 556
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): add support for oauth client
- Loading branch information
1 parent
8c3a56f
commit b8192c6
Showing
6 changed files
with
56 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { FetchError, OAuthClient } from '@atproto/oauth-client' | ||
import { XRPCError } from '@atproto/xrpc' | ||
import { SessionManager } from './session-manager' | ||
|
||
export class OAuthSessionManager implements SessionManager { | ||
constructor(readonly client: OAuthClient) {} | ||
|
||
async fetchHandler(url: string, init: RequestInit): Promise<Response> { | ||
try { | ||
return await this.client.request(url, init) | ||
} catch (cause) { | ||
if (cause instanceof FetchError) { | ||
throw new XRPCError( | ||
cause.statusCode, | ||
undefined, | ||
cause.message, | ||
undefined, | ||
{ cause }, | ||
) | ||
} | ||
throw cause | ||
} | ||
} | ||
|
||
async getServiceUrl(): Promise<URL> { | ||
return new URL(this.client.serverMetadata.issuer) | ||
} | ||
|
||
async getDid(): Promise<string> { | ||
const { sub } = await this.client.getTokenSet() | ||
return sub | ||
} | ||
} |
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.