Esempio n. 1
0
        public async Task <Credentials> Reauthorize()
        {
            if (credentials == null || credentials?.RefreshToken.Length == 0)
            {
                return(await Authorize().ConfigureAwait(false));
            }

            RequestSignature sig = GenerateRequestSignature();

            Response.ApiResponse <Credentials> response = await api.RefreshAccessToken(
                credentials.RefreshToken,
                sig.Signature,
                sig.Timestamp)
                                                          .ConfigureAwait(false);

            if (!response.IsSuccess)
            {
                throw new ResponseException(response.ResponseMessage, response.ResponseCode);
            }

            credentials           = response.Result;
            credentials.Timestamp = response.Timestamp;

            return(credentials);
        }
Esempio n. 2
0
        public async Task <Credentials> Authorize()
        {
            RequestSignature sig = GenerateRequestSignature();

            Response.ApiResponse <Credentials> response = await api.GetAccessToken(
                sig.Signature,
                sig.Timestamp)
                                                          .ConfigureAwait(false);

            if (!response.IsSuccess)
            {
                throw new ResponseException(response.ResponseMessage, response.ResponseCode);
            }

            credentials           = response.Result;
            credentials.Timestamp = response.Timestamp;

            return(credentials);
        }
Esempio n. 3
0
        public async Task <DeviceInfo> GetDeviceInfo(string deviceId)
        {
            if (credentials == null || credentials?.AccessToken.Length == 0)
            {
                throw new UnauthorizedException("Unauthorized");
            }

            RequestSignature sig = GenerateRequestSignature(credentials.AccessToken);

            Response.ApiResponse <DeviceInfo> response = await api.GetDeviceInfo(
                sig.Signature,
                sig.Timestamp,
                credentials.AccessToken,
                deviceId)
                                                         .ConfigureAwait(false);

            if (!response.IsSuccess)
            {
                throw new ResponseException(response.ResponseMessage, response.ResponseCode);
            }

            return(response.Result);
        }