-
Notifications
You must be signed in to change notification settings - Fork 11
Support custom PDSs #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,19 +16,22 @@ namespace Bluesky.NET.ApiClients; | |
| public partial class BlueskyApiClient : IBlueskyApiClient | ||
| { | ||
| private readonly HttpClient _httpClient = new(); | ||
| private string _baseUrl = "https://bsky.social"; | ||
|
|
||
| public async Task<Result<AuthResponse>> RefreshAsync(string refreshToken) | ||
| public async Task<Result<AuthResponse>> RefreshAsync(string refreshToken, string baseUrl = UrlConstants.BlueskyBaseUrl) | ||
| { | ||
| var refreshUrl = $"{UrlConstants.BlueskyBaseUrl}/{UrlConstants.RefreshAuthPath}"; | ||
| _baseUrl = baseUrl; | ||
| var refreshUrl = $"{baseUrl}/{UrlConstants.RefreshAuthPath}"; | ||
| HttpRequestMessage message = new(HttpMethod.Post, refreshUrl); | ||
| message.Headers.Authorization = new AuthenticationHeaderValue("Bearer", refreshToken); | ||
| return await PostAuthMessageAsync(message); | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public async Task<Result<AuthResponse>> AuthenticateAsync(string identifer, string appPassword) | ||
| public async Task<Result<AuthResponse>> AuthenticateAsync(string identifer, string appPassword, string baseUrl = UrlConstants.BlueskyBaseUrl) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments here as the comment on RefreshAsync |
||
| { | ||
| var authUrl = $"{UrlConstants.BlueskyBaseUrl}/{UrlConstants.AuthPath}"; | ||
| _baseUrl = baseUrl; | ||
| var authUrl = $"{baseUrl}/{UrlConstants.AuthPath}"; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This url is resolving to |
||
|
|
||
| var requestBody = new AuthRequestBody | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||
| using Bluesky.NET.ApiClients; | ||||||
| using Bluesky.NET.Constants; | ||||||
| using Bluesky.NET.Models; | ||||||
| using BlueskyClient.Constants; | ||||||
| using FluentResults; | ||||||
|
|
@@ -53,7 +54,7 @@ public async Task<Result<AuthResponse>> TrySilentSignInAsync() | |||||
| string? storedAppPassword = _secureCredentialStorage.GetCredential(AppPasswordCredentialKey(storedDid)); | ||||||
| if (storedAppPassword is { Length: > 0 }) | ||||||
| { | ||||||
| result = await SignInWithValidatedCredentialsAsync(storedDid, storedAppPassword); | ||||||
| result = await SignInWithValidatedCredentialsAsync(storedDid, storedAppPassword, _secureCredentialStorage.GetCredential(BaseURLCredentialKey(storedDid))); | ||||||
| } | ||||||
|
|
||||||
| return result; | ||||||
|
|
@@ -67,6 +68,7 @@ public void SignOut() | |||||
| { | ||||||
| _secureCredentialStorage.SetCredential(storedDid, string.Empty); | ||||||
| _secureCredentialStorage.SetCredential(AppPasswordCredentialKey(storedDid), string.Empty); | ||||||
| _secureCredentialStorage.SetCredential(BaseURLCredentialKey(storedDid), string.Empty); | ||||||
| } | ||||||
|
|
||||||
| _userSettings.Set(UserSettingsConstants.LocalUserIdKey, string.Empty); | ||||||
|
|
@@ -77,7 +79,7 @@ public void SignOut() | |||||
| } | ||||||
|
|
||||||
| /// <inheritdoc/> | ||||||
| public async Task<Result<AuthResponse>> SignInAsync(string rawUserHandleOrEmail, string rawPassword) | ||||||
| public async Task<Result<AuthResponse>> SignInAsync(string rawUserHandleOrEmail, string rawPassword, string? baseUrl) | ||||||
| { | ||||||
| var userHandleOrEmail = rawUserHandleOrEmail.Trim().TrimStart('@'); | ||||||
| var password = rawPassword.Trim(); | ||||||
|
|
@@ -87,7 +89,7 @@ public async Task<Result<AuthResponse>> SignInAsync(string rawUserHandleOrEmail, | |||||
| return Result.Fail<AuthResponse>("Empty identifier or password"); | ||||||
| } | ||||||
|
|
||||||
| return await SignInWithValidatedCredentialsAsync(userHandleOrEmail, password); | ||||||
| return await SignInWithValidatedCredentialsAsync(userHandleOrEmail, password, baseUrl ?? "bsky.social"); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After making my recommended changes on
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| public async Task<Result<string>> TryGetFreshTokenAsync() | ||||||
|
|
@@ -142,9 +144,9 @@ private void UpdateStoredToken(AuthResponse response) | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| private async Task<Result<AuthResponse>> SignInWithValidatedCredentialsAsync(string identifier, string password) | ||||||
| private async Task<Result<AuthResponse>> SignInWithValidatedCredentialsAsync(string identifier, string password, string? baseUrl) | ||||||
| { | ||||||
| Result<AuthResponse> result = await _apiClient.AuthenticateAsync(identifier, password); | ||||||
| Result<AuthResponse> result = await _apiClient.AuthenticateAsync(identifier, password, baseUrl ?? "bsky.social"); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| if (result.IsSuccess) | ||||||
| { | ||||||
|
|
@@ -154,6 +156,9 @@ private async Task<Result<AuthResponse>> SignInWithValidatedCredentialsAsync(str | |||||
| { | ||||||
| _userSettings.Set(UserSettingsConstants.SignedInDIDKey, did); | ||||||
| _secureCredentialStorage.SetCredential(AppPasswordCredentialKey(did), password); | ||||||
| _secureCredentialStorage.SetCredential( | ||||||
| BaseURLCredentialKey(did), | ||||||
| baseUrl ?? UrlConstants.BlueskyBaseUrl); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -162,4 +167,5 @@ private async Task<Result<AuthResponse>> SignInWithValidatedCredentialsAsync(str | |||||
|
|
||||||
|
|
||||||
| private static string AppPasswordCredentialKey(string did) => $"{did}-appPassword"; | ||||||
| private static string BaseURLCredentialKey(string did) => $"{did}-baseUrl"; | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommend making the following changes:
string? baseUrl = null. Make sure to apply this change in the interface as well._baseUrl = baseUrl ?? UrlConstants.BlueskyBaseUrl;{_baseUrl}/{UrlConstants.RefreshAuthPath}