Skip to content
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 42 commits into from
Mar 7, 2025

Conversation

amitksingh1490
Copy link
Contributor

@amitksingh1490 amitksingh1490 commented Mar 4, 2025

No description provided.

@amitksingh1490 amitksingh1490 changed the title feat(oauth): implement OAuth authentication flow with login and logou… feat(oauth): implement authentication flow with login and logout Mar 4, 2025
@amitksingh1490 amitksingh1490 marked this pull request as ready for review March 4, 2025 14:24
@@ -0,0 +1,19 @@
use anyhow::Result;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to app

@@ -63,6 +67,18 @@ impl<F: App + Infrastructure> API for ForgeAPI<F> {
self.app.conversation_service().create(workflow).await
}

async fn login(&self) -> anyhow::Result<()> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
async fn login(&self) -> anyhow::Result<()> {
async fn authenticate(&self) -> anyhow::Result<()> {

fn logout(&self) -> anyhow::Result<bool>;

/// Checks if the user is currently authenticated
fn is_authenticated(&self) -> bool;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete it

let (auth_url, pkce_verifier, csrf_token, _nonce) = self.generate_auth_url();

// 2. Open browser for user authentication
println!("Opening browser for authentication...");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove println

}

/// Complete the OAuth2 flow and return the token and user info
pub async fn complete_auth_flow(&self) -> Result<()> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub async fn complete_auth_flow(&self) -> Result<()> {
pub async fn complete_auth_flow(&self) -> Result<URL> {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be split this flow in two parts one to create the URL and other to actually login. api.rs needs to be changed

// 7. create a new key
let client = reqwest::Client::new();
let key: Key = client
.put("https://antinomy.ai/api/v1/key")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url in new should come as argument

}

impl Default for ClerkConfig {
fn default() -> Self {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implement new with config as argument

@@ -118,6 +119,62 @@ impl<F: API> UI<F> {
input = self.console.prompt(prompt_input).await?;
continue;
}
Command::Login => {
info!("Starting OAuth authentication flow...");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make logging consistent with our existing formats


Self { or, cache: Cache::new(1024) }
fn build_provider_service(&self) -> Result<Self> {
if self.or.is_some() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will never be some.

or: Box<dyn ProviderService>,
pub struct ForgeProviderService<F> {
infra: Arc<F>,
or: Option<Arc<dyn ProviderService>>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
or: Option<Arc<dyn ProviderService>>,
or: Option<Arc<P>>,

Don't use dyn.

self.or
this.or
.as_ref()
.ok_or_else(|| anyhow::anyhow!("Provider service not initialized"))?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate error messages. Move them to a common place.

tusharmath and others added 16 commits March 6, 2025 13:46
…method names with repository pattern

- Rename AuthService to CredentialRepository for better semantic clarity
- Change method names from init_auth/logout to create/delete to align with repository pattern
- Update method call sites across the codebase
- Refactor AuthFlowState to encapsulate internal implementation details
…handling

- Refactor Provider enum with hierarchical OpenAiCompat structure
- Improve URL handling with proper Url type and consistent API
- Simplify ClientBuilder implementation and authentication flow
- Consolidate provider identification with helper methods
@tusharmath tusharmath enabled auto-merge (squash) March 7, 2025 04:36
@tusharmath tusharmath merged commit 14dac83 into main Mar 7, 2025
9 checks passed
tusharmath added a commit that referenced this pull request Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants