Skip to content

Commit

Permalink
Merge pull request #40 from chemokita13/fix_login
Browse files Browse the repository at this point in the history
Fix login
  • Loading branch information
chemokita13 authored Apr 26, 2024
2 parents b90c343 + 9c61ab0 commit 5988a31
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 89 deletions.
110 changes: 42 additions & 68 deletions src/BeFake/BeFake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@ export default class BeFake {
headers: any; // axios headers
firebaseToken: any; // Firebase token
dataPath: string; // Path to the data folder
sign: string; // Signature for the requests

constructor(tokenObj: tokenObj = null, deviceId = null) {
tokenObj && this.loadToken(tokenObj); // load token if provided
(this.disable_ssl = false),
(this.deviceId = deviceId || this._generateRandomDeviceId()),
(this.api_url = 'https://mobile.bereal.com/api'),
(this.google_api_key = 'AIzaSyDwjfEeparokD7sXPVQli9NsTuhT6fJ6iA'),
(this.google_api_key = 'AIzaSyCgNTZt6gzPMh-2voYXOvrt_UR_gpGl83Q'),
(this.headers = {
'user-agent':
'BeReal/1.0.1 (AlexisBarreyat.BeReal; build:9513; iOS 16.0.2) 1.0.0/BRApriKit',
'x-ios-bundle-identifier': 'AlexisBarreyat.BeReal',
});
this.dataPath = 'programData';
this.sign = 'MToxNzEzNzEyODgwOjxnCJdewCldXQkgQ/eI0ju6j+S5qUeVZ7GaepOzma2O';
}

// Generate a random device id, (random string with 16chars)
Expand All @@ -52,88 +54,60 @@ export default class BeFake {
}

async sendOtpCloud(phoneNumber: string): Promise<BeFakeResponse> {

try {
const firstData = JSON.stringify({
appToken:
const firstData = {
"appToken":
'54F80A258C35A916B38A3AD83CA5DDD48A44BFE2461F90831E0F97EBA4BB2EC7',
});
};
const firstUrl =
'https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyClient?key=' +
this.google_api_key;
const firstReq = await fetch(firstUrl, {
method: 'POST',
body: firstData,
headers: {
'content-type': 'application/json',
accept: '*/*',
'x-client-version':
'iOS/FirebaseSDK/9.6.0/FirebaseCore-iOS',
'x-ios-bundle-identifier': 'AlexisBarreyat.BeReal',
'accept-language': 'en',
'user-agent':
'FirebaseAuth.iOS/9.6.0 AlexisBarreyat.BeReal/0.31.0 iPhone/14.7.1 hw/iPhone9_1',
'x-firebase-locale': 'en',
'x-firebase-gmpid': '1:405768487586:ios:28c4df089ca92b89',
},
});
if (!firstReq.ok) {
sendMail(
'firstReq not ok',
JSON.stringify(await firstReq.json()),
);
return {
done: false,
msg: 'Something went wrong',
};
const headers = {
"content-type": "application/json",
"accept": "*/*",
"x-client-version": "iOS/FirebaseSDK/9.6.0/FirebaseCore-iOS",
"x-ios-bundle-identifier": "AlexisBarreyat.BeReal",
"accept-language": "en",
"user-agent": "FirebaseAuth.iOS/9.6.0 AlexisBarreyat.BeReal/0.31.0 iPhone/14.7.1 hw/iPhone9_1",
"x-firebase-locale": "en",
"x-firebase-gmpid": "1:405768487586:ios:28c4df089ca92b89",
"bereal-app-version-code": "14549",
"bereal-signature": this.sign,
"bereal-device-id": "937v3jb942b0h6u9",
"bereal-timezone": "Europe/Paris",
}
const firstResponse = await firstReq.json();
const receipt = firstResponse.receipt;
const secondData = JSON.stringify({
phoneNumber: phoneNumber,
iosReceipt: receipt,
});

const firstResponse = await axios.post(firstUrl, firstData, {
headers, validateStatus: function (status) {
return true
},
})
const rec = firstResponse.data.receipt
const secondUrl =
'https://www.googleapis.com/identitytoolkit/v3/relyingparty/sendVerificationCode?key=' +
this.google_api_key;
const secondReq = await fetch(secondUrl, {
method: 'POST',
body: secondData,
headers: {
'content-type': 'application/json',
accept: '*/*',
'x-client-version':
'iOS/FirebaseSDK/9.6.0/FirebaseCore-iOS',
'x-ios-bundle-identifier': 'AlexisBarreyat.BeReal',
'accept-language': 'en',
'user-agent':
'FirebaseAuth.iOS/9.6.0 AlexisBarreyat.BeReal/0.28.2 iPhone/14.7.1 hw/iPhone9_1',
'x-firebase-locale': 'en',
'x-firebase-gmpid': '1:405768487586:ios:28c4df089ca92b89',
},
});
if (!secondReq.ok) {
// sendMail(
// 'secondReq not ok',
// JSON.stringify(await secondReq.json()),
// );
return {
done: false,
msg: 'Something went wrong',
};
const secondData = {
"phoneNumber": phoneNumber,
"iosReceipt": rec,
}
const secondResponse = await secondReq.json();
this.otpSession = secondResponse.sessionInfo;
const secondResponse = await axios.post(secondUrl, secondData, {
headers, validateStatus: function (status) {
return true
},
})
return {
done: true,
msg: 'OTP code sent',
data: { otpSession: secondResponse.sessionInfo },
data: { otpSession: secondResponse.data },
};

} catch (error) {
return {
done: false,
msg: 'Something went wrong',
data: error,
};
msg: "Something went wrong when loggin",
"data": error
}
}
}

Expand All @@ -143,7 +117,7 @@ export default class BeFake {
'content-type': 'application/json',
'x-firebase-client':
'apple-platform/ios apple-sdk/19F64 appstore/true deploy/cocoapods device/iPhone9,1 fire-abt/8.15.0 fire-analytics/8.15.0 fire-auth/8.15.0 fire-db/8.15.0 fire-dl/8.15.0 fire-fcm/8.15.0 fire-fiam/8.15.0 fire-fst/8.15.0 fire-fun/8.15.0 fire-install/8.15.0 fire-ios/8.15.0 fire-perf/8.15.0 fire-rc/8.15.0 fire-str/8.15.0 firebase-crashlytics/8.15.0 os-version/14.7.1 xcode/13F100',
accept: '*/*',
'accept': '*/*',
'x-client-version': 'iOS/FirebaseSDK/8.15.0/FirebaseCore-iOS',
'x-firebase-client-log-type': '0',
'x-ios-bundle-identifier': 'AlexisBarreyat.BeReal',
Expand Down Expand Up @@ -489,7 +463,7 @@ export default class BeFake {
Authorization: 'Bearer ' + this.token,
"bereal-app-version-code": "14549",
"bereal-signature":
"MToxNzEyOTQxMTkzOu75viungWtmbUPjGRoFkfFbDfqLKzyx8f/ayv2KR54K",
this.sign,
"bereal-timezone": "Europe/Paris",
"bereal-device-id": "937v3jb942b0h6u9",
},
Expand Down
53 changes: 32 additions & 21 deletions src/login/login.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { APIresponse, tokenObj } from 'src/types/types';

@Injectable()
export class LoginService {
constructor(private jwtService: JwtService) {} // Constructor with jwtService
constructor(private jwtService: JwtService) { } // Constructor with jwtService

// Get tokens object and return token
public async tokenize(tokenObj: tokenObj): Promise<string> {
Expand Down Expand Up @@ -39,27 +39,38 @@ export class LoginService {
}

public async sendCode(body: { phone: string }): Promise<APIresponse> {
try {
const bf = new BeFake();
const response: BeFakeResponse = await bf.sendOtpCloud(body.phone);
if (response.done) {
return {
status: 201,
message: 'OTP sent',
data: response.data,
};
}
throw new Error(response.data || response.msg);
} catch (error) {
throw new HttpException(
{
status: 400,
message: 'OTP not sent',
data: error.data,
},
400,
);
// try {
const bf = new BeFake();
const response: BeFakeResponse = await bf.sendOtpCloud(body.phone);
console.log(body.phone)
console.log(response.data)
if (response.done) {
return {
status: 201,
message: 'OTP sent',
data: response.data,
};
}
throw new HttpException(
{
status: 400,
message: 'OTP not sent',
data: response.data,
},
400,

);
// } catch (error) {
// console.log(error.data)
// throw new HttpException(
// {
// status: 400,
// message: 'OTP not sent',
// data: error.data,
// },
// 400,
// );
// }
}

public async sendVonageCode(body: { phone: string }): Promise<APIresponse> {
Expand Down

0 comments on commit 5988a31

Please sign in to comment.