/// <summary> /// Creates tokenized URL query. /// </summary> /// <param name="serviceUrl">Initial query</param> /// <param name="token">Token value</param> /// <returns> /// Tokenized query string. /// </returns> public static string FormatTokenQuery(string query, string token) { Debug.Assert(query != null); Debug.Assert(token != null); StringBuilder sb = new StringBuilder(query); RestHelper.AddQueryParam(QUERY_TOKEN, token, sb, true); return(sb.ToString()); }
/// <summary> /// Get request for token. /// </summary> /// <param name="credentials">Credentials.</param> /// <returns>String with requests for token.</returns> private static string _GetTokenCommonQueryString(NetworkCredential credentials) { StringBuilder query = new StringBuilder(); RestHelper.AddQueryParam(QUERY_REQUEST, QUERY_GETTOKEN, query, true); RestHelper.AddQueryParam(QUERY_USERNAME, credentials.UserName, query, true); RestHelper.AddQueryParam(QUERY_PASSWORD, credentials.Password, query, true); RestHelper.AddQueryParam(QUERY_FORMAT, JSON_FORMAT, query, true); return(query.ToString()); }
/// <summary> /// Get server token using request where "referer" is specified. /// </summary> /// <param name="tokenServiceURL">Token service URL.</param> /// <param name="credentials">Credentials to get token.</param> /// <returns>Token from service.</returns> public static Token GetServerTokenUsingReferer(string tokenServiceURL, NetworkCredential credentials) { Debug.Assert(tokenServiceURL != null); Debug.Assert(credentials != null); StringBuilder query = new StringBuilder(_GetTokenCommonQueryString(credentials)); RestHelper.AddQueryParam(QUERY_EXPIRATION, EXPIRATION_IN_MINUTES, query, true); RestHelper.AddQueryParam(QUERY_CLIENT, REFERER_PARAMETER_NAME, query, true); RestHelper.AddQueryParam(REFERER_PARAMETER_NAME, RefererValue, query, true); HttpRequestOptions opt = new HttpRequestOptions(); opt.Method = HttpMethod.Post; opt.UseGZipEncoding = false; opt.Timeout = GET_TOKEN_TIMEOUT; var response = WebHelper.SendRequest(tokenServiceURL, query.ToString(), opt); return(_ParseTokenResponse(response)); }