Beispiel #1
0
        private bool SaveToken(WebTokenRequestResult wtrr, string resource)
        {
            if (wtrr.ResponseStatus == WebTokenRequestStatus.Success)
            {
                if (resource == null)
                {
                    resource = DefaultResource;
                }

                if (!_tokens.ContainsKey(resource))
                {
                    _tokens.Add(resource, new TokenInfo());
                }

                _tokens[resource].Token = GetTokenFromResult(wtrr);
                CachedProperties.Clear();

                if (wtrr.ResponseData != null)
                {
                    foreach (var data in wtrr.ResponseData)
                    {
                        CachedProperties = new Dictionary <string, string>(data.Properties);

                        if (data.Properties.TryGetValue("exp", out string unixTimeString))
                        {
                            var dt = DateTimeOffset.FromUnixTimeSeconds(Convert.ToUInt32(unixTimeString));
                            _tokens[resource].ExpiresOn = dt.DateTime.ToLocalTime();
                            ServiceUtil.LogService.Write($"Resource: {resource}, Token Expiration: {_tokens[resource].ExpiresOn}");
                        }

                        _isSignedIn = true;
                        TokenUpdate?.Invoke(this, new EventArgs());
                        return(true);
                    }
                }
            }

            _isSignedIn = false;
            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Update This updates the entity with the given properties. Only those properties which should be updated can be provided. The &#39;id&#39; and &#39;version&#39; are required to identify the entity.
        /// </summary>
        /// <exception cref="Wallee.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="spaceId"></param>
        /// <param name="entity">The object with all the properties which should be updated. The id and the version are required properties.</param>
        /// <returns>ApiResponse of Token</returns>
        public ApiResponse <Token> UpdateWithHttpInfo(long?spaceId, TokenUpdate entity)
        {
            // verify the required parameter 'spaceId' is set
            if (spaceId == null)
            {
                throw new ApiException(400, "Missing required parameter 'spaceId' when calling TokenService->Update");
            }
            // verify the required parameter 'entity' is set
            if (entity == null)
            {
                throw new ApiException(400, "Missing required parameter 'entity' when calling TokenService->Update");
            }

            var    localVarPath         = "/token/update";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(this.Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json;charset=utf-8"
            };
            String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json;charset=utf-8"
            };
            String localVarHttpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (spaceId != null)
            {
                localVarQueryParams.AddRange(this.Configuration.ApiClient.ParameterToKeyValuePairs("", "spaceId", spaceId));                  // query parameter
            }
            if (entity != null && entity.GetType() != typeof(byte[]))
            {
                localVarPostBody = this.Configuration.ApiClient.Serialize(entity); // http body (model) parameter
            }
            else
            {
                localVarPostBody = entity; // byte array
            }


            this.Configuration.ApiClient.ResetTimeout();
            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)this.Configuration.ApiClient.CallApi(localVarPath,
                                                                                                 Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                 localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("Update", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <Token>(localVarStatusCode,
                                           localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                           (Token)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(Token))));
        }
Beispiel #3
0
        /// <summary>
        /// Update This updates the entity with the given properties. Only those properties which should be updated can be provided. The &#39;id&#39; and &#39;version&#39; are required to identify the entity.
        /// </summary>
        /// <exception cref="Wallee.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="spaceId"></param>
        /// <param name="entity">The object with all the properties which should be updated. The id and the version are required properties.</param>
        /// <returns>Token</returns>
        public Token Update(long?spaceId, TokenUpdate entity)
        {
            ApiResponse <Token> localVarResponse = UpdateWithHttpInfo(spaceId, entity);

            return(localVarResponse.Data);
        }