/// <summary> /// /// </summary> /// <returns></returns> protected override ADPAccessToken getAccessToken() { ADPAccessToken token = accessToken; AuthorizationCodeConfiguration conconfig = (AuthorizationCodeConfiguration)connectionConfiguration; Dictionary <string, string> data = null; AuthenticationHeaderValue credentials = null; if (!isConnectedIndicator()) { data = new Dictionary <string, string>(); data.Add("client_id", conconfig.clientID); data.Add("client_secret", conconfig.clientSecret); data.Add("grant_type", conconfig.grantType); data.Add("code", conconfig.authorizationCode); data.Add("redirect_uri", conconfig.redirectURL); var encodedCredentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(String.Format("{0}:{1}", connectionConfiguration.clientID, connectionConfiguration.clientSecret))); var result = SendWebRequest(conconfig.tokenServerURL, data, credentials); if (!String.IsNullOrEmpty(result)) { token = JSONUtil.Deserialize <ADPAccessToken>(result); Status = "connected"; } } return(token); }
/// <summary> /// /// </summary> /// <param name="ADPProductURL"></param> /// <returns></returns> public override string getADPData(string ADPProductURL) { string serverResponse = null; ADPAccessToken token = getAccessToken(); Dictionary <string, string> data = null; if (isConnectedIndicator() && (token != null)) { data = new Dictionary <string, string>(); data.Add("client_id", ((AuthorizationCodeConfiguration)connectionConfiguration).clientID); data.Add("client_secret", ((AuthorizationCodeConfiguration)connectionConfiguration).clientSecret); data.Add("grant_type", ((AuthorizationCodeConfiguration)connectionConfiguration).grantType); data.Add("code", ((AuthorizationCodeConfiguration)connectionConfiguration).authorizationCode); data.Add("redirect_uri", ((AuthorizationCodeConfiguration)connectionConfiguration).redirectURL); // send the data to ADP server/s // since we have a valid token serverResponse = SendWebRequest(ADPProductURL, data, new AuthenticationHeaderValue(token.TokenType, token.AccessToken), "application/json", "GET"); } else { throw new ADPConnectionException("Connection Exception: connection not established."); } return(serverResponse); }
/// <summary> /// /// </summary> public void connect() { if (connectionConfiguration == null) { throw new ADPConnectionException("Configuration not provided."); } this.accessToken = this.getAccessToken(); }
/// <summary> /// /// </summary> /// <returns></returns> public virtual bool isConnectedIndicator() { if (accessToken != null) { // we have a valid token so check if it expired if (DateTime.Compare(DateTime.Now, accessToken.ExpiresOn.Value) > 0) { // token expires so set to null accessToken = null; } } return(accessToken != null); }
/// <summary> /// /// </summary> /// <param name="ADPProductURL"></param> /// <returns></returns> public virtual string getADPData(string ADPProductURL) { string serverResponse = null; ADPAccessToken token = getAccessToken(); Dictionary <string, string> data = null; if (isConnectedIndicator() && (token != null)) { // send the data to ADP server/s // since we have a valid token serverResponse = SendWebRequest(ADPProductURL, data, new AuthenticationHeaderValue(token.TokenType, token.AccessToken), "application/json", "GET"); } else { throw new ADPConnectionException("Connection Exception: connection not established."); } return(serverResponse); }
/// <summary> /// /// </summary> /// <returns>valid ADPAccessToken</returns> protected virtual ADPAccessToken getAccessToken() { ADPAccessToken token = accessToken; Dictionary <string, string> data = null; AuthenticationHeaderValue credentials = null; if (!isConnectedIndicator()) { if (String.IsNullOrEmpty(connectionConfiguration.grantType)) { throw new ADPConnectionException("ADP Connection Exception: config option grantType cannot be null/empty"); } if (String.IsNullOrEmpty(connectionConfiguration.tokenServerURL)) { throw new ADPConnectionException("ADP Connection Exception: config option tokenServerURL cannot be null/empty"); } data = new Dictionary <string, string>(); data.Add("client_id", connectionConfiguration.clientID); data.Add("client_secret", connectionConfiguration.clientSecret); data.Add("grant_type", connectionConfiguration.grantType); // send the data to ADP server/s var result = SendWebRequest(connectionConfiguration.tokenServerURL, data, credentials); if (!String.IsNullOrEmpty(result)) { token = JSONUtil.Deserialize <ADPAccessToken>(result); } } // if valid token from session or // token not expired return it. return(token); }
/// <summary> /// /// </summary> public void disconnect() { this.accessToken = null; }