-
Notifications
You must be signed in to change notification settings - Fork 21
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
feat(oauth): implement authentication flow with login and logout #442
Merged
Merged
Changes from 26 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
a68a5fd
feat(oauth): implement OAuth authentication flow with login and logou…
amitksingh1490 d40a03d
fix: add missing commas and format code for better readability
amitksingh1490 3269c3b
feat(auth): implement OAuth authentication service with login and log…
amitksingh1490 7481c31
Merge remote-tracking branch 'origin/main' into feat/integrate-auth
amitksingh1490 2dbd0eb
chore: update dependencies in Cargo.lock
amitksingh1490 5570f6b
chore: update dependencies in Cargo.lock to remove unused packages an…
amitksingh1490 dba4b16
[autofix.ci] apply automated fixes
autofix-ci[bot] 928a12d
chore: remove unused forge_oauth dependency from Cargo.toml and Cargo…
amitksingh1490 ff4c259
chore: remove unused test module for keyring functionality in oauth.rs
amitksingh1490 9f1e7cb
chore: add MockAuthService to test infrastructure in attachment.rs
amitksingh1490 863060e
chore: update reqwest dependency to version 0.12.12 and enable rustls…
amitksingh1490 0871b1f
Merge branch 'main' into feat/integrate-auth
amitksingh1490 535c0cc
feat: implement unimplemented methods in AuthService and add get_auth…
amitksingh1490 49e9ad5
feat: update get_auth_token to return Option<String> and add support …
amitksingh1490 59ef2e0
Merge branch 'main' into feat/integrate-auth
amitksingh1490 23b39f6
[autofix.ci] apply automated fixes
autofix-ci[bot] ddbc64d
fix(provider): simplify condition check for 'or' in build_provider_se…
amitksingh1490 4c9dff9
[autofix.ci] apply automated fixes
autofix-ci[bot] 27f8f17
Merge remote-tracking branch 'origin/main' into feat/integrate-auth
amitksingh1490 a9e41bf
refactor(auth): improve error handling and remove unnecessary print s…
amitksingh1490 743d05a
feat(oauth): integrate forge_oauth crate and update authentication flow
amitksingh1490 c379e75
feat(auth): update ClerkConfig initialization and add key_url paramet…
amitksingh1490 d5bbe13
refactor(auth): format code for better readability in ForgeAuthServic…
amitksingh1490 934864e
refactor(ui): remove unnecessary log statements from authentication flow
amitksingh1490 4423721
fix(provider): correct base URL for Antinomy provider
amitksingh1490 63cd373
refactor(api): simplify imports by using wildcard for forge_domain
amitksingh1490 c025f1f
refactor(auth): rename authentication methods for clarity and consist…
tusharmath 37159f9
[autofix.ci] apply automated fixes
autofix-ci[bot] 6d2d6cc
refactor: add mutex in ForgeProviderService
tusharmath e888edd
refactor(auth): rename auth_service to credentials_service for clarity
tusharmath 4a133ed
refactor(auth): rename AuthService to CredentialRepository and align …
tusharmath 671cc1f
[autofix.ci] apply automated fixes
autofix-ci[bot] e3a79bc
refactor(provider): replace ProviderBuilder with ClientBuilder and re…
tusharmath 8cbb5d9
refactor(api): simplify header construction by consolidating API key …
amitksingh1490 377065f
refactor(api): enhance models method to handle multiple provider resp…
amitksingh1490 b44bc33
refactor(provider): reorganize provider structure and authentication …
tusharmath d6cffd5
refactor(api): update provider match to use OpenAiCompat for Antinomy
amitksingh1490 3d61cfa
refactor(provider): update OpenRouter URL to new endpoint
amitksingh1490 6e96822
refactor(provider): fix Antinomy URL formatting and update environmen…
amitksingh1490 05e1bb1
refactor(auth): update Clerk OAuth configuration with new URLs and cl…
amitksingh1490 bea131b
feat(html): add new HTML templates for error handling and success mes…
tusharmath 97fe923
[autofix.ci] apply automated fixes
autofix-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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 |
---|---|---|
|
@@ -8,47 +8,85 @@ use forge_domain::{ | |
use forge_open_router::ProviderBuilder; | ||
use moka2::future::Cache; | ||
|
||
use crate::{EnvironmentService, Infrastructure}; | ||
use crate::{AuthService, EnvironmentService, Infrastructure}; | ||
|
||
pub struct ForgeProviderService { | ||
or: Box<dyn ProviderService>, | ||
pub struct ForgeProviderService<F> { | ||
infra: Arc<F>, | ||
or: Option<Arc<dyn ProviderService>>, | ||
cache: Cache<ModelId, Parameters>, | ||
} | ||
|
||
impl ForgeProviderService { | ||
pub fn new<F: Infrastructure>(infra: Arc<F>) -> Self { | ||
let env = infra.environment_service().get_environment(); | ||
let or = ProviderBuilder::from_url(env.provider_url) | ||
.with_key(env.provider_key) | ||
.build() | ||
.expect("Failed to build provider"); | ||
impl<F: Infrastructure> ForgeProviderService<F> { | ||
pub fn new(infra: Arc<F>) -> Self { | ||
let infra = infra.clone(); | ||
Self { infra, or: None, cache: Cache::new(1024) } | ||
} | ||
|
||
fn with_provider_service(&self, provider: Arc<dyn ProviderService>) -> Self { | ||
Self { | ||
infra: self.infra.clone(), | ||
or: Some(provider), | ||
cache: self.cache.clone(), | ||
} | ||
} | ||
|
||
Self { or, cache: Cache::new(1024) } | ||
fn build_provider_service(&self) -> Result<Self> { | ||
if self.or.is_some() { | ||
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 will never be |
||
return Ok(Self { | ||
infra: self.infra.clone(), | ||
or: self.or.clone(), | ||
cache: self.cache.clone(), | ||
}); | ||
} | ||
let env = self.infra.environment_service().get_environment(); | ||
let key = if let Some(_antinomy) = env.force_antinomy { | ||
self.infra | ||
.auth_service() | ||
.get_auth_token() | ||
.ok_or_else(|| anyhow::anyhow!("No auth token found run login command to login"))? | ||
} else { | ||
env.provider_key.clone() | ||
}; | ||
let or = ProviderBuilder::from_url(env.provider_url) | ||
.with_key(key) | ||
.build()?; | ||
Ok(self.with_provider_service(or)) | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl ProviderService for ForgeProviderService { | ||
impl<F: Infrastructure> ProviderService for ForgeProviderService<F> { | ||
async fn chat( | ||
&self, | ||
model_id: &ModelId, | ||
request: ChatContext, | ||
) -> ResultStream<ChatCompletionMessage, anyhow::Error> { | ||
self.or | ||
let this: ForgeProviderService<F> = self.build_provider_service()?; | ||
this.or | ||
.as_ref() | ||
.ok_or_else(|| anyhow::anyhow!("Provider service not initialized"))? | ||
.chat(model_id, request) | ||
.await | ||
.with_context(|| format!("Failed to chat with model: {}", model_id)) | ||
} | ||
|
||
async fn models(&self) -> Result<Vec<Model>> { | ||
self.or.models().await | ||
let this = self.build_provider_service()?; | ||
this.or | ||
.as_ref() | ||
.ok_or_else(|| anyhow::anyhow!("Provider service not initialized"))? | ||
.models() | ||
.await | ||
} | ||
|
||
async fn parameters(&self, model: &ModelId) -> anyhow::Result<Parameters> { | ||
Ok(self | ||
let this = self.build_provider_service()?; | ||
Ok(this | ||
.cache | ||
.try_get_with_by_ref(model, async { | ||
self.or | ||
this.or | ||
.as_ref() | ||
.ok_or_else(|| anyhow::anyhow!("Provider service not initialized"))? | ||
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. Duplicate error messages. Move them to a common place. |
||
.parameters(model) | ||
.await | ||
.with_context(|| format!("Failed to get parameters for model: {}", model)) | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Don't use
dyn
.