diff --git a/README.md b/README.md index 1facdf7..ddfb4dc 100644 --- a/README.md +++ b/README.md @@ -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 ;-) diff --git a/package.json b/package.json index 8a02edd..ed2dfec 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.ts b/src/index.ts index fb4d95a..68e8296 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,16 +3,16 @@ * * 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. @@ -20,8 +20,8 @@ import axios, { AxiosRequestConfig, AxiosResponse } from "axios"; * - 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" }; /** @@ -104,11 +104,6 @@ export class Life360Handler { * @returns Life360 `Auth` object */ async login(): Promise { - // this.username = username || ""; - // this.password = password || ""; - // this.phonenumber = phonenumber || ""; - // this.countryCode = countryCode || 1; - // Reset access token this.auth = { access_token: "", @@ -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" });