diff --git a/src/app/services/api.service.ts b/src/app/services/api.service.ts index 11042fa0..a4561a7a 100644 --- a/src/app/services/api.service.ts +++ b/src/app/services/api.service.ts @@ -19,13 +19,13 @@ */ import { Injectable } from '@angular/core' -import { APIRequest, FormDataContainer, Method, RefreshTokenRequest } from '../requests/requests' +import { APIRequest, ApiTokenResponse, FormDataContainer, Method, RefreshTokenRequest } from '../requests/requests' import { StorageService } from './storage.service' import { ApiNetwork } from '../models/StorageTypes' import { isDevMode } from '@angular/core' import { Mutex } from 'async-mutex' import { findConfigForKey, MAP } from '../utils/NetworkData' -import { CapacitorHttp, HttpResponse } from '@capacitor/core' +import { Capacitor, CapacitorHttp, HttpResponse } from '@capacitor/core' import { CacheModule } from '../utils/CacheModule' import axios, { AxiosResponse } from 'axios' import { HttpOptions } from '@capacitor/core' @@ -154,9 +154,27 @@ export class ApiService extends CacheModule { const now = Date.now() const req = new RefreshTokenRequest(user.refreshToken) - const resp = await this.execute(req) - const response = req.parse(resp) - const result = response[0] + + let result: ApiTokenResponse + let resp + if (Capacitor.isNativePlatform() && Capacitor.getPlatform() == 'android') { + const formBody = new FormData() + formBody.set('grant_type', 'refresh_token') + formBody.set('refresh_token', user.refreshToken) + const url = await this.getResourceUrl(req.resource, req.endPoint) + + resp = await fetch(url, { + method: 'POST', + body: formBody, + headers: await this.getAuthHeader(true), + }) + result = await resp.json() + } else { + + resp = await this.execute(req) + const response = req.parse(resp) + result = response[0] + } console.log('Refresh token', result, resp) if (!result || !result.access_token) {