Ejemplo n.º 1
0
        private void SetCredentials(TokenOptions iamTokenOptions, string serviceUrl = null)
        {
            if (iamTokenOptions.IamApiKey.StartsWith(ICP_PREFIX))
            {
                SetCredentials(APIKEY_AS_USERNAME, iamTokenOptions.IamApiKey, serviceUrl);
            }
            else
            {
                if (!string.IsNullOrEmpty(serviceUrl))
                {
                    Url = serviceUrl;
                }
                _iamUrl       = !string.IsNullOrEmpty(iamTokenOptions.IamUrl) ? iamTokenOptions.IamUrl : "https://iam.bluemix.net/identity/token";
                _iamTokenData = new IamTokenData();

                if (!string.IsNullOrEmpty(iamTokenOptions.IamApiKey))
                {
                    _iamApiKey = iamTokenOptions.IamApiKey;
                }

                if (!string.IsNullOrEmpty(iamTokenOptions.IamAccessToken))
                {
                    this._userAcessToken = iamTokenOptions.IamAccessToken;
                }

                GetToken();
            }
        }
Ejemplo n.º 2
0
        private void OnRefreshIamTokenResponse(RESTConnector.Request req, RESTConnector.Response resp)
        {
            IamTokenData result = new IamTokenData();
            fsData       data   = null;
            Dictionary <string, object> customData = ((RefreshIamTokenRequest)req).CustomData;

            customData.Add(Constants.String.RESPONSE_HEADERS, resp.Headers);

            if (resp.Success)
            {
                try
                {
                    fsResult r = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data);
                    if (!r.Succeeded)
                    {
                        throw new WatsonException(r.FormattedMessages);
                    }

                    object obj = result;
                    r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
                    if (!r.Succeeded)
                    {
                        throw new WatsonException(r.FormattedMessages);
                    }

                    customData.Add("json", data);
                }
                catch (Exception e)
                {
                    Log.Error("TokenManager.OnRefreshTokenResponse()", "Exception: {0}", e.ToString());
                    resp.Success = false;
                }
            }

            if (resp.Success)
            {
                if (((RefreshIamTokenRequest)req).SuccessCallback != null)
                {
                    ((RefreshIamTokenRequest)req).SuccessCallback(result, customData);
                }
            }
            else
            {
                if (((RefreshIamTokenRequest)req).FailCallback != null)
                {
                    ((RefreshIamTokenRequest)req).FailCallback(resp.Error, customData);
                }
            }
        }
Ejemplo n.º 3
0
        private void SetCredentials(TokenOptions iamTokenOptions, string serviceUrl = null)
        {
            if (!string.IsNullOrEmpty(serviceUrl))
                Url = serviceUrl;
            _iamUrl = !string.IsNullOrEmpty(iamTokenOptions.IamUrl) ? iamTokenOptions.IamUrl : "https://iam.bluemix.net/identity/token";
            _iamTokenData = new IamTokenData();

            if (!string.IsNullOrEmpty(iamTokenOptions.IamApiKey))
                _iamApiKey = iamTokenOptions.IamApiKey;

            if (!string.IsNullOrEmpty(iamTokenOptions.IamAccessToken))
                this._userAcessToken = iamTokenOptions.IamAccessToken;

            GetToken();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Constructor that takes IAM token options.
        /// </summary>
        /// <param name="iamTokenOptions"></param>
        public Credentials(TokenOptions iamTokenOptions, string serviceUrl)
        {
            Url           = serviceUrl;
            _iamUrl       = !string.IsNullOrEmpty(iamTokenOptions.IamUrl) ? iamTokenOptions.IamUrl : "https://iam.bluemix.net/identity/token";
            _iamTokenData = new IamTokenData();

            if (!string.IsNullOrEmpty(iamTokenOptions.IamApiKey))
            {
                _iamApiKey = iamTokenOptions.IamApiKey;
            }

            if (!string.IsNullOrEmpty(iamTokenOptions.IamAccessToken))
            {
                this._userAcessToken = iamTokenOptions.IamAccessToken;
            }

            GetToken();
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Save the response from the IAM service request to the object's state.
 /// </summary>
 /// <param name="iamTokenData">Response object from IAM service request</param>
 public void SaveTokenInfo(IamTokenData iamTokenData)
 {
     TokenData = iamTokenData;
 }
Ejemplo n.º 6
0
 private void OnGetToken(IamTokenData iamTokenData, Dictionary <string, object> customData)
 {
     SaveTokenInfo(iamTokenData);
 }