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

Rethinking on auth plugin contract #1

Open
msp98 opened this issue May 5, 2024 · 4 comments
Open

Rethinking on auth plugin contract #1

msp98 opened this issue May 5, 2024 · 4 comments

Comments

@msp98
Copy link

msp98 commented May 5, 2024

Right now the auth plugin has lots of loginWith methods.

loginWithGoogle()
loginWithMeta()
loginWithApple()
loginWithTwitter()
loginWithGithub()
loginWithLinkedin()
loginWithMicrosoft()

Which might grow as soon as we want to add a new provider method. And this functionality is "closed"(in OCP terms), but not open for adding new providers.
A better way would be to open the plugin interface for adding a provider implementation, and accept a contract for login, logout etc.
This way the core plugin contract will not have to worry about adding new providers, as and when required, keeping the abstractions at the heart and extensibility at the consumer end.

@pavanpodila
Copy link
Contributor

Can you take a first cut at the contract ? We can iterate on that

@Sourav-nonstop
Copy link

Define Interface:

abstract class AuthProvider {
  Future<void> login();
  Future<void> logout();
}

Implement Providers:

class GoogleAuthProvider implements AuthProvider {
  @override
  Future<void> login() async {
    // Google login implementation
  }

  @override
  Future<void> logout() async {
    // Google logout implementation
  }
}

class MetaAuthProvider implements AuthProvider {
  @override
  Future<void> login() async {
    // Meta login implementation
  }

  @override
  Future<void> logout() async {
    // Meta logout implementation
  }
}

And we can use DIP to use AuthProvider everywhere

void authenticate(AuthProvider provider) {
  provider.login();
}

@msp98 are you suggesting something like this?
I am starting this

@pavanpodila
Copy link
Contributor

How will the interface look for the following login providers:

  • email/password
  • passwordless
  • SAML within Org

the login method is where we can add arguments to specifically deal with provider specific details, so a Map<String, dynamic> will be required for the login method ..

@pavanpodila
Copy link
Contributor

We got one step closer with the use of the loginWithOAuth(OAuthType type) method to handle all OAuth signins...reduces the methods from 7 to 1 for all OAuth integrations...needs more work though on adding scopes but can be integrated easily once the use case comes up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants