/// <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="JSONConfigObject"></param> /// <returns></returns> public override ConnectionConfiguration init(String JSONConfigObject) { AuthorizationCodeConfiguration ccfg = JSONUtil.Deserialize <AuthorizationCodeConfiguration>(JSONConfigObject); this.clientID = ccfg.clientID; this.clientSecret = ccfg.clientSecret; this.sslCertPath = ccfg.sslCertPath; this.sslKeyPass = ccfg.sslKeyPass; this.tokenServerURL = ccfg.tokenServerURL; this.apiRequestURL = ccfg.apiRequestURL; // this.tokenExpiration = ccfg.tokenExpiration; this.accessScope = ccfg.accessScope; return(ccfg); }
/// <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); }