loginViaApple method

  1. @override
Future<RequestResponse<FrappeSessionStatusInfo?>> loginViaApple({
  1. required String code,
  2. required APPLE_OPTION option,
  3. String? state,
})
override

Logins in using Apple Auth code.

In addition to the code, the option must be specified APPLE_OPTION.

Optionally pass the state which is usually a JWT or base64 encoded data.

Implementation

@override
Future<RequestResponse<FrappeSessionStatusInfo?>> loginViaApple({
  required String code,
  required APPLE_OPTION option,
  String? state,
}) async {
  await getFrappe().checkAppInstalled(features: ['loginViaApple']);

  assert(code.isNotEmpty, 'Code cannot be empty');

  final response = await Request.initiateRequest(
      url: config.hostUrl,
      method: HttpMethod.POST,
      contentType: ContentTypeLiterals.APPLICATION_JSON,
      data: <String, dynamic>{
        'cmd': 'renovation_core.oauth.login_via_apple',
        'code': code,
        'option': EnumToString.convertToString(option),
        'state': state,
        'use_jwt': _useJwt
      },
      isFrappeResponse: false);

  FrappeSessionStatusInfo? sessionStatusInfo;
  if (response.isSuccess) {
    sessionStatusInfo = FrappeSessionStatusInfo.fromJson(
        Request.convertToMap(response.rawResponse!));
    sessionStatusInfo.rawSession =
        Request.convertToMap(response.rawResponse!);
  }
  updateSession(
      sessionStatus: sessionStatusInfo, loggedIn: response.isSuccess);
  return response.isSuccess
      ? RequestResponse.success(sessionStatusInfo,
          rawResponse: response.rawResponse)
      : RequestResponse.fail(response.error!);
}