コード例 #1
0
ファイル: IamTokenManager.cs プロジェクト: Yu713/daimon
        /// <summary>
        /// Request an IAM token using an API key.
        /// </summary>
        /// <param name="callback">The request callback.</param>
        /// <param name="error"> The request error.</param>
        /// <returns></returns>
        override protected bool RequestToken(Callback <TokenData> callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("successCallback");
            }

            RESTConnector connector = new RESTConnector();

            connector.URL = url;
            if (connector == null)
            {
                return(false);
            }

            RequestIamTokenRequest req = new RequestIamTokenRequest();

            req.Callback   = callback;
            req.HttpMethod = UnityWebRequest.kHttpVerbGET;
            req.Headers.Add("Content-type", "application/x-www-form-urlencoded");
            req.Headers.Add("Authorization", Utility.CreateAuthorization(iamClientId, iamClientSecret));
            req.OnResponse             = OnRequestIamTokenResponse;
            req.DisableSslVerification = disableSslVerification;
            req.Forms = new Dictionary <string, RESTConnector.Form>();
            req.Forms["grant_type"]    = new RESTConnector.Form("urn:ibm:params:oauth:grant-type:apikey");
            req.Forms["apikey"]        = new RESTConnector.Form(iamApikey);
            req.Forms["response_type"] = new RESTConnector.Form("cloud_iam");

            return(connector.Send(req));
        }
コード例 #2
0
        public override void Validate()
        {
            if (string.IsNullOrEmpty(Url))
            {
                throw new ArgumentNullException(string.Format(ErrorMessagePropMissing, "Url"));
            }

            if (string.IsNullOrEmpty(Username))
            {
                throw new ArgumentNullException(string.Format(ErrorMessagePropMissing, "Username"));
            }

            if (string.IsNullOrEmpty(Password))
            {
                throw new ArgumentNullException(string.Format(ErrorMessagePropMissing, "Password"));
            }

            if (Utility.HasBadFirstOrLastCharacter(Url))
            {
                throw new ArgumentException(string.Format(ErrorMessagePropInvalid, "Url"));
            }

            if (Utility.HasBadFirstOrLastCharacter(Username))
            {
                throw new ArgumentException(string.Format(ErrorMessagePropInvalid, "Username"));
            }

            if (Utility.HasBadFirstOrLastCharacter(Password))
            {
                throw new ArgumentException(string.Format(ErrorMessagePropInvalid, "Password"));
            }
        }
コード例 #3
0
        private bool RequestToken(Callback <CloudPakForDataTokenResponse> callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("successCallback");
            }

            RESTConnector connector = new RESTConnector();

            connector.URL = Url;
            if (connector == null)
            {
                return(false);
            }

            RequestCloudPakForDataTokenRequest req = new RequestCloudPakForDataTokenRequest();

            req.HttpMethod = UnityWebRequest.kHttpVerbGET;
            req.Callback   = callback;
            req.Headers.Add("Content-type", "application/x-www-form-urlencoded");
            req.Headers.Add("Authorization", Utility.CreateAuthorization(Username, Password));
            req.OnResponse             = OnRequestCloudPakForDataTokenResponse;
            req.DisableSslVerification = DisableSslVerification;
            return(connector.Send(req));
        }
コード例 #4
0
ファイル: IamAuthenticator.cs プロジェクト: HAC-2020/Vikings
        /// <summary>
        /// Request an IAM token using an API key.
        /// </summary>
        /// <param name="callback">The request callback.</param>
        /// <returns></returns>
        bool RequestToken(Callback <IamTokenResponse> callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("successCallback");
            }

            RESTConnector connector = new RESTConnector();

            connector.URL = Url;
            if (connector == null)
            {
                return(false);
            }

            RequestIamTokenRequest req = new RequestIamTokenRequest();

            req.Callback   = callback;
            req.HttpMethod = UnityWebRequest.kHttpVerbGET;
            req.Headers.Add("Content-type", "application/x-www-form-urlencoded");
            // If both the clientId and secret were specified by the user, then use them.
            if (!string.IsNullOrEmpty(ClientId) && !string.IsNullOrEmpty(ClientSecret))
            {
                req.Headers.Add("Authorization", Utility.CreateAuthorization(ClientId, ClientSecret));
            }
            req.OnResponse             = OnRequestIamTokenResponse;
            req.DisableSslVerification = DisableSslVerification;
            req.Forms               = new Dictionary <string, RESTConnector.Form>();
            req.Forms[GrantType]    = new RESTConnector.Form(RequestGrantType);
            req.Forms[ApikeyConst]  = new RESTConnector.Form(Apikey);
            req.Forms[ResponseType] = new RESTConnector.Form(CloudIam);

            return(connector.Send(req));
        }
コード例 #5
0
ファイル: RESTConnector.cs プロジェクト: HAC-2020/Vikings
 /// <summary>
 /// Add Authentication headers
 /// </summary>
 /// <param name="username">Username</param>
 /// <param name="password">Password.</param>
 public void WithAuthentication(string username, string password)
 {
     if (Headers == null)
     {
         Headers = new Dictionary <string, string>();;
     }
     Headers[AUTHENTICATION_AUTHORIZATION_HEADER] = Utility.CreateAuthorization(username, password);
 }
コード例 #6
0
        public override void Validate()
        {
            if (string.IsNullOrEmpty(BearerToken))
            {
                throw new ArgumentNullException(string.Format(ErrorMessagePropMissing, "BearerToken"));
            }

            if (Utility.HasBadFirstOrLastCharacter(BearerToken))
            {
                throw new ArgumentException(string.Format(ErrorMessagePropInvalid, "BearerToken"));
            }
        }
コード例 #7
0
ファイル: RESTConnector.cs プロジェクト: HAC-2020/Vikings
        /// <summary>
        /// This function returns a RESTConnector object for the given service and function.
        /// </summary>
        /// <param name="authenticator">Authenticator used to authenticate service.</param>
        /// <param name="function">The name of the function.</param>
        /// <param name="serviceUrl">Service Url to connect to.</param>
        /// <returns>Returns a RESTConnector object or null on error.</returns>
        ///
        public static RESTConnector GetConnector(Authenticator authenticator, string function, string serviceUrl)
        {
            if (string.IsNullOrEmpty(serviceUrl))
            {
                throw new ArgumentNullException("The serviceUrl must not be empty or null.");
            }

            if (Utility.HasBadFirstOrLastCharacter(serviceUrl))
            {
                throw new ArgumentException("The serviceUrl property is invalid. Please remove any surrounding {{, }}, or \" characters.");
            }

            RESTConnector connector = new RESTConnector
            {
                URL            = serviceUrl + function,
                Authentication = authenticator
            };

            authenticator.Authenticate(connector);
            return(connector);
        }
コード例 #8
0
ファイル: IamAuthenticator.cs プロジェクト: HAC-2020/Vikings
        public override void Validate()
        {
            if (string.IsNullOrEmpty(Apikey))
            {
                throw new ArgumentNullException(string.Format(ErrorMessagePropMissing, "apikey"));
            }

            if (Utility.HasBadFirstOrLastCharacter(Apikey))
            {
                throw new ArgumentException(string.Format(ErrorMessagePropInvalid, "apikey"));
            }

            if (Utility.HasBadFirstOrLastCharacter(Url))
            {
                throw new ArgumentException(string.Format(ErrorMessagePropInvalid, "url"));
            }

            if (!string.IsNullOrEmpty(ClientSecret) && string.IsNullOrEmpty(ClientId) || string.IsNullOrEmpty(ClientSecret) && !string.IsNullOrEmpty(ClientId))
            {
                throw new ArgumentException("Client ID and Secret must BOTH be provided.");
            }
        }