Skip to content

Commit

Permalink
Modifications for Life360 API changes
Browse files Browse the repository at this point in the history
* Updated Life360 Client secret

* Updated API endpoints and login API call.

* Bugfix for issue #7
  • Loading branch information
MiGoller authored Jun 10, 2022
1 parent fda7ac4 commit 659f093
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ main();

## Changelog

0.1.2

- (MiGoller) Bugfix for issue [#7](https://github.com/MiGoller/life360-api.js/issues/7) after Life360 updated API

0.1.0

- (MiGoller) First public release. Enjoy ;-)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "life360-api.js",
"version": "0.1.1",
"version": "0.1.2",
"description": "An unofficial client for the Life360 API.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
27 changes: 15 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
*
* Author: MiGoller
*
* Copyright (c) 2021 MiGoller
* Copyright (c) 2022 MiGoller
*/

/* eslint-disable @typescript-eslint/no-explicit-any */
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";

/**
* Hard-coded "CLIENT_SECRET" in https://www.life360.com/circles/scripts/ef464e2a.scripts.js !
* Hard-coded "CLIENT_SECRET": Has to be identified and verified after Life360 publishes a new version of the mobile app!
*/
const LIFE360_CLIENT_SECRET = "U3dlcUFOQWdFVkVoVWt1cGVjcmVrYXN0ZXFhVGVXckFTV2E1dXN3MzpXMnZBV3JlY2hhUHJlZGFoVVJhZ1VYYWZyQW5hbWVqdQ==";
const LIFE360_CLIENT_SECRET = "YnJ1czR0ZXZhcHV0UmVadWNydUJSVXdVYnJFTUVDN1VYZTJlUEhhYjpSdUt1cHJBQ3JhbWVzV1UydVRyZVF1bXVtYTdhemFtQQ==";

/**
* The Life360 API URIs.
* - login URL
* - circles URL
*/
const ENDPOINT = {
"LOGIN": "https://www.life360.com/v3/oauth2/token.json",
"CIRCLES": "https://www.life360.com/v3/circles"
"LOGIN": "https://api-cloudfront.life360.com/v3/oauth2/token.json",
"CIRCLES": "https://api-cloudfront.life360.com/v3/circles"
};

/**
Expand Down Expand Up @@ -104,11 +104,6 @@ export class Life360Handler {
* @returns Life360 `Auth` object
*/
async login(): Promise<any> {
// this.username = username || "";
// this.password = password || "";
// this.phonenumber = phonenumber || "";
// this.countryCode = countryCode || 1;

// Reset access token
this.auth = {
access_token: "",
Expand All @@ -117,14 +112,22 @@ export class Life360Handler {

let response: any;

const authData = {
grant_type: "password",
username: this.username,
password: this.password,
countryCode: this.countryCode,
phone: this.phonenumber
};

try {
response = await axios.request({
url: ENDPOINT.LOGIN,
method: "POST",
data: `countryCode=${this.countryCode}&username=${this.username}&phone=${this.phonenumber}&password=${this.password}&grant_type=password`,
data: authData,
headers: {
"Authorization": `Authorization: Basic ${LIFE360_CLIENT_SECRET}`,
"Content-Type" : "application/x-www-form-urlencoded"
"Content-Type" : "application/json"
},
responseType: "json"
});
Expand Down

0 comments on commit 659f093

Please sign in to comment.