homey-api 3.4.35 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -543,6 +543,63 @@ for(const {@link HomeyAPIV2.ManagerDevices.Device device} of Object.values(devic
543
543
  return this.__token;
544
544
  }
545
545
 
546
+ async authenticateWithExtendedGrantType(grantType, grantParams) {
547
+ if (!grantParams) {
548
+ throw new Error('Missing Params');
549
+ }
550
+ if (!grantType) {
551
+ throw new Error('Missing Grant Type');
552
+ }
553
+
554
+ if (!this.__clientId) {
555
+ throw new Error('Missing Client ID');
556
+ }
557
+
558
+ if (!this.__clientSecret) {
559
+ throw new Error('Missing Client Secret');
560
+ }
561
+
562
+ const params = {
563
+ grant_type: grantType,
564
+ ...grantParams,
565
+ }
566
+
567
+ const response = await Util.fetch(`${this.baseUrl}/oauth2/token`, {
568
+ body: Util.encodeUrlSearchParams(params),
569
+ method: 'post',
570
+ headers: {
571
+ Authorization: `Basic ${Util.base64(`${this.__clientId}:${this.__clientSecret}`)}`,
572
+ 'Content-Type': 'application/x-www-form-urlencoded',
573
+ },
574
+ });
575
+
576
+ let responseBody;
577
+ try {
578
+ responseBody = await response.json();
579
+ } catch (err) {
580
+ this.__debug(`Invalid response from server (${response.status}): ${response.text()}`);
581
+ throw new APIError(`Invalid response from server: ${response.text()}`, response.status);
582
+ }
583
+
584
+ if (!response.ok) {
585
+ throw new APIError(responseBody.error_description || responseBody.error, response.status);
586
+ }
587
+
588
+ this.__token = new Token({
589
+ token_type: responseBody.token_type,
590
+ access_token: responseBody.access_token,
591
+ refresh_token: responseBody.refresh_token,
592
+ expires_in: responseBody.expires_in,
593
+ grant_type: grantType,
594
+ });
595
+
596
+ this.__setStore({
597
+ token: this.__token,
598
+ });
599
+
600
+ return this.__token;
601
+ }
602
+
546
603
  async authenticateWithRefreshToken() {
547
604
  if (!this.__refreshTokenPromise) {
548
605
  this.__refreshTokenPromise = Promise.resolve().then(async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homey-api",
3
- "version": "3.4.35",
3
+ "version": "3.5.0",
4
4
  "description": "Homey API",
5
5
  "main": "index.js",
6
6
  "files": [