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

is there any examples #4

Closed
Emperor577 opened this issue Sep 18, 2021 · 5 comments
Closed

is there any examples #4

Emperor577 opened this issue Sep 18, 2021 · 5 comments

Comments

@Emperor577
Copy link

could you please share some example? how to use it step by step for beginners. Thank you

@mishatron
Copy link
Owner

mishatron commented Sep 20, 2021

could you please share some example? how to use it step by step for beginners. Thank you

yes, I can provide some example in library description, but a bit later this week. I put some code here for you

class AuthRepositoryImpl extends AuthRepository {
  final String _clientAudience;
  Auth0Client _auth;

  AuthRepositoryImpl(String baseUrl, String clientId, this._clientAudience) {
    _auth = Auth0Client(
        clientId: clientId,
        domain: baseUrl,
        connectTimeout: timeout.inMilliseconds,
        sendTimeout: timeout.inMilliseconds,
        useLoggerInterceptor: false,
        receiveTimeout: 60000);
  }

  @override
  Future<dynamic> register(String login, String password) async {
    dynamic response = await _auth.createUser({
      'email': login,
      'password': password,
      'connection': 'Username-Password-Authentication'
    });
  }

  @override
  Future<Auth0User> login(String login, String password) async {
    Auth0User response = await _auth.passwordRealm({
      'username': login,
      'password': password,
      'scope': 'openid email profile offline_access',
      'audience': _clientAudience,
      'realm': 'Username-Password-Authentication'
    });
    await PreferenceManager().setAccessToken(response.accessToken);
    await PreferenceManager().setRefreshToken(response.refreshToken);
    return response;
  }

  @override
  Future<dynamic> getUserInfo() async {
    dynamic response = await _auth.getUserInfo();
    return response;
  }

  @override
  Future<String> refreshToken(String refreshToken) async {
    dynamic response = await _auth.refreshToken({"refreshToken": refreshToken});
    await PreferenceManager().setAccessToken(response["access_token"]);
    return response["access_token"];
  }

  @override
  Future<dynamic> logout() async {
    await PreferenceManager().clear();
    var response = await _auth.logout();
    return response;
  }

  @override
  Future<String> resetPassword(String login) async {
    dynamic response = await _auth.resetPassword(
        {'email': login, 'connection': 'Username-Password-Authentication'});
    return response;
  }

  @override
  void setBearer(String token) {
    _auth.updateToken(token);
  }
}

@yasinarik
Copy link

I was just reading it and decided to write the same comment with Dart formatting for better visuals.

class AuthRepositoryImpl extends AuthRepository {
  final String _clientAudience;
  Auth0Client _auth;

  AuthRepositoryImpl(String baseUrl, String clientId, this._clientAudience) {
    _auth = Auth0Client(
        clientId: clientId,
        domain: baseUrl,
        connectTimeout: timeout.inMilliseconds,
        sendTimeout: timeout.inMilliseconds,
        useLoggerInterceptor: false,
        receiveTimeout: 60000);
  }

  @override
  Future<dynamic> register(String login, String password) async {
    dynamic response = await _auth.createUser({
      'email': login,
      'password': password,
      'connection': 'Username-Password-Authentication'
    });
  }

  @override
  Future<Auth0User> login(String login, String password) async {
    Auth0User response = await _auth.passwordRealm({
      'username': login,
      'password': password,
      'scope': 'openid email profile offline_access',
      'audience': _clientAudience,
      'realm': 'Username-Password-Authentication'
    });
    await PreferenceManager().setAccessToken(response.accessToken);
    await PreferenceManager().setRefreshToken(response.refreshToken);
    return response;
  }

  @override
  Future<dynamic> getUserInfo() async {
    dynamic response = await _auth.getUserInfo();
    return response;
  }

  @override
  Future<String> refreshToken(String refreshToken) async {
    dynamic response = await _auth.refreshToken({"refreshToken": refreshToken});
    await PreferenceManager().setAccessToken(response["access_token"]);
    return response["access_token"];
  }

  @override
  Future<dynamic> logout() async {
    await PreferenceManager().clear();
    var response = await _auth.logout();
    return response;
  }

  @override
  Future<String> resetPassword(String login) async {
    dynamic response = await _auth.resetPassword(
        {'email': login, 'connection': 'Username-Password-Authentication'});
    return response;
  }

  @override
  void setBearer(String token) {
    _auth.updateToken(token);
  }
}

@mishatron
Copy link
Owner

thanks for the contributing

@rohsaurus
Copy link

Sorry if this question was already answered or if the answer was obvious, but when I used the sample code above, dart is having an issue finding the AuthRepository class (the class that is being extended). Where do I find this class that is being expanded.

For imports, I only have the auth0 import: import 'package:auth0/auth0.dart';

Thanks in advance.

@mishatron
Copy link
Owner

Sorry if this question was already answered or if the answer was obvious, but when I used the sample code above, dart is having an issue finding the AuthRepository class (the class that is being extended). Where do I find this class that is being expanded.

For imports, I only have the auth0 import: import 'package:auth0/auth0.dart';

Thanks in advance.

This is an example. AuthRepository is in abstract class (like an interface). You could use it as you want

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

4 participants