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

[GROOMING] Contact synchonization v2 #2171

Open
hoangdat opened this issue Dec 5, 2024 · 6 comments
Open

[GROOMING] Contact synchonization v2 #2171

hoangdat opened this issue Dec 5, 2024 · 6 comments
Assignees
Labels
FT::CONTACT Features connected to contacts and contact list

Comments

@hoangdat
Copy link
Member

hoangdat commented Dec 5, 2024

Desc:

DoD:

  • Synchronize contact to web app
@hoangdat hoangdat changed the title Contact synchonization [GROOMING] Contact synchonization v2 Dec 5, 2024
@hoangdat hoangdat added the FT::CONTACT Features connected to contacts and contact list label Dec 5, 2024
@hoangdat
Copy link
Member Author

hoangdat commented Dec 5, 2024

  • hashDetails: n peppers
{
  "algorithms": [
    "none",
    "sha256"
  ],
  "lookup_pepper": "matrixrocks",
  "alt_lookup_peppers": ["oldmatrixrocks"]
}
  • 1 pid <-> n hash: Map<String, List<String>: map between pid to each hash of this

@hoangdat
Copy link
Member Author

hoangdat commented Dec 5, 2024

class ThirdPartyLookupAPI {
  Future<Response> lookup(baseUrl, accessToken, List<CalculatedHash>) {
    // create + setup dio
    // get response from thirdparty 
  }
}

@hoangdat
Copy link
Member Author

  1. How to extract Fed server in well-known?
  2. How Contact Manager work in case Fed available, or not?
  3. How to work with Fed server?
  • how to get token for Fed server?
  • how to handle this token when it is expired?
  1. How to get /hash_details in Fed?
  2. How to fetch /look_up in Fed?
  3. How to handle mappings in /look_up response?
  4. How to handle third_party_mappings in /look_up response?

@nqhhdev nqhhdev self-assigned this Dec 26, 2024
@nqhhdev
Copy link
Member

nqhhdev commented Dec 26, 2024

How to extract Fed server in well-know

  • ENDPOINT {{homeserver}}.well-known/matrix/client

  • Response

{
    ...
    "m.federated_identity_services": {
        "base_urls": [
            "https://fed...com/"
        ]
    },
    ...
}

Create Fed server info:

@JsonSerializable()
class FedServerInformation with EquatableMixin {
  static const String fedServerKey = 'm.federated_identity_services';

  @JsonKey(name: 'base_url')
  final Uri? baseUrl;

  @JsonKey(name: 'server_name')
  final String? serverName;

  FedServerInformation({
    this.baseUrl,
    this.serverName,
  });

  factory FedServerInformation.fromJson(Map<String, dynamic> json) =>
      _$FedServerInformationFromJson(json);

  Map<String, dynamic> toJson() => _$FedServerInformationToJson(this);

  @override
  List<Object?> get props => [baseUrl, serverName];
}

Create FedConfigurations

class FedConfigurations with EquatableMixin {
  final FedServerInformation fedServerInformation;
  final IdentityServerInformation? identityServerInformation;
  final String? authUrl;
  final LoginType? loginType;

  FedConfigurations({
    required this.tomServerInformation,
    this.identityServerInformation,
    this.authUrl,
    this.loginType,
  });

  @override
  List<Object?> get props =>
      [fedServerInformation, identityServerInformation, authUrl, loginType];
}

Convert response from .well-know to FedServerInformation

  • Write func convert it in HomeserverSummaryExtensions: lib/domain/model/extensions/homeserver_summary_extensions.dart
FedServerInformation? get fedServer {
    if (discoveryInformation?.additionalProperties == null) {
      return null;
    }
    final fedServerJson = discoveryInformation
        ?.additionalProperties[FedServerInformation.fedServerKey];
    if (fedServerJson == null) {
      return null;
    }
    try {
      return FedServerInformation.fromJson(fedServerJson);
    } catch (e) {
      Logs().e('Failed to parse m.federated_identity_services from homeserver summary', e);
      return null;
    }
  }

Create FedConfigurationsRepository

abstract class FedConfigurationsRepository {
  Future<FedConfigurations> getFedConfigurations(String userId);

  Future<void> saveFedConfigurations(
    String userId,
    FedConfigurations fedConfigurations,
  );

  Future<void> deleteFedConfigurations(String userId);
}

Create new Fed dio in NetworkDI

class NetworkDI extends BaseDI {
  static const fedServerUrlInterceptorName = 'fedServerDynamicUrlInterceptor';
  static const fedServerDioName = 'fedServerDioName';
  static const fedDioClientName = 'fedServerDioClientName';

  void _bindInterceptor(GetIt get) { 
    get.registerLazySingleton(
      () => DynamicUrlInterceptors(),
      instanceName: fedServerUrlInterceptorName,
    );
  }

  void _bindDio(GetIt get) {
    _bindDioForFedServer(get);
  }

  void _bindDioForFedServer(GetIt Get) {}
}

@nqhhdev
Copy link
Member

nqhhdev commented Dec 27, 2024

How to work with Fed server

Request Fed token

  • Use URL {{identityServer}}_matrix/client/v3/user/{{mxid}}/openid/request_token to call get Fed Token information

Response

{
    "access_token": "pXoIqYPEUwRUTMUAkjWMMIgF",
    "token_type": "Bearer",
    "matrix_server_name": "stg.lin-saas.com",
    "expires_in": 3600
}

Create FedAuthorizationInterceptor to handle accessToken after call request Fed token

class FedAuthorizationInterceptor extends InterceptorsWrapper {
  FedAuthorizationInterceptor();

  String? _accessToken;

  set accessToken(String? accessToken) {
    _accessToken = accessToken;
  }

  @override
  void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
    options.headers[HttpHeaders.authorizationHeader] = _bearerToken;
    Logs().d('FedAuthorizationInterceptor::onRequest:accessToken: $_bearerToken');
    super.onRequest(options, handler);
  }

  String get _bearerToken => 'Bearer $_accessToken';
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FT::CONTACT Features connected to contacts and contact list
Projects
None yet
Development

No branches or pull requests

2 participants