/// <summary> /// Method to initialize IdentifyServiceManager interfaces with user login credentials. /// </summary> /// <param name="consumerKey">The consumer key.</param> /// <param name="consumerSecretKey">The consumer secret key.</param> /// <returns> /// IdentifyServiceManager /// </returns> public static IdentifyServiceManager getInstance(String consumerKey, String consumerSecretKey) { if (serviceManager == null) { OAuthFactory.setInstance(new BaseOAuthServiceImpl(consumerKey, consumerSecretKey)); serviceManager = new IdentifyServiceManager(); Debug.WriteLine("Identify Service instance has been created"); } Debug.WriteLine("Identify Service instance has been already created"); return(serviceManager); }
/// <summary> /// Gets the instance of IdentifyServiceManager. /// </summary> /// <param name="baseOAuthService">The base oAuth service.</param> /// <returns> /// IdentifyServiceManager /// </returns> public static IdentifyServiceManager getInstance(BaseOAuthService baseOAuthService) { if (serviceManager == null) { OAuthFactory.setInstance(baseOAuthService); serviceManager = new IdentifyServiceManager(); Debug.WriteLine("Identify Service instance has been created"); } Debug.WriteLine("Identify Service instance has been already created"); return(serviceManager); }
/// <summary> /// Processes the API Request Object. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="url">The URL.</param> /// <param name="inputaddress">inputaddress String</param> /// <returns>string</returns> public static string processAPIRequestInternal <T>(String url, String inputaddress) { String endPoint = String.Empty; String contentTypeString = String.Empty; SdkException exception = null; JavaScriptSerializer serializer = new JavaScriptSerializer(); try { String accessToken = OAuthFactory.getOAuthService().getAuthenticationToken(); //Add xml API fragment string to complete the endpoint for xml input endPoint = url + Constants.API_FRAGMENT_JSON; contentTypeString = "application/json;charset=utf-8"; Uri uri = new Uri(endPoint); using (ExtendedWebClient client = new ExtendedWebClient()) { client.Headers.Add(HttpRequestHeader.ContentType, contentTypeString); client.Headers.Add(Constants.AUTH_HEADER, accessToken); client.Headers.Add(Constants.USER_AGENT, "CSharp-SDK"); String resp = (client.UploadString(uri, inputaddress)); return(resp); } } catch (WebException webException) { Debug.WriteLine("Got an error response from API" + webException); string responseText = string.Empty; int statusCode = 0; if (webException.Response != null) { var responseStream = webException.Response.GetResponseStream(); statusCode = (int)((HttpWebResponse)webException.Response).StatusCode; using (var reader = new StreamReader(responseStream)) { responseText = reader.ReadToEnd(); } try { ErrorInfo apiError; apiError = serializer.Deserialize <ErrorInfo>(responseText); if (apiError != null) { apiError.HttpStatusCode = statusCode; apiError.Reason = webException.Message; apiError.Response = responseText; } exception = new SdkException(apiError); } catch (Exception e) { Debug.WriteLine("Unexpected Error: " + e); exception = new SdkException(new SdkInternalError(Constants.ERROR_MSG_API_PROCESSING, e)); } } else { Debug.WriteLine("Unexpected Error: " + webException); exception = new SdkException(new SdkInternalError(Constants.ERROR_MSG_API_PROCESSING, webException)); } } catch (Exception e) { Debug.WriteLine("Unexpected Error: " + e); exception = new SdkException(new SdkInternalError(Constants.ERROR_MSG_API_PROCESSING, e)); } throw exception; }
public OAuthController(IHttpContextAccessor contextAccessor, ILogger <OAuthController> logger, OAuthFactory oauthFactory) { this._context = contextAccessor.HttpContext; this._logger = logger; this._oauth = oauthFactory.Get("hduhelp"); }