A convenience class to help with the signature generation used in the D2L authentication system
コード例 #1
0
        public IEnumerable <Tuple <string, string> > CreateAuthenticatedTokens(Uri fullUrl, string httpMethod)
        {
            long adjustedTimestampSeconds = GetAdjustedTimestampInSeconds();

            string signature = FormatSignature(fullUrl.AbsolutePath, httpMethod, adjustedTimestampSeconds);

            Func <string, string, Tuple <string, string> > createTuple =
                (s0, s1) => new Tuple <string, string>(s0, s1);

            var tokens = new List <Tuple <string, string> > {
                createTuple(APP_ID_PARAMETER, m_appId)
            };

            if (m_userId != null)
            {
                tokens.Add(createTuple(USER_ID_PARAMETER, m_userId));
                tokens.Add(
                    createTuple(
                        SIGNATURE_BY_USER_KEY_PARAMETER,
                        D2LSigner.GetBase64HashString(m_userKey, signature)
                        )
                    );
            }
            tokens.Add(createTuple(SIGNATURE_BY_APP_KEY_PARAMETER, D2LSigner.GetBase64HashString(m_appKey, signature)));
            tokens.Add(createTuple(TIMESTAMP_PARAMETER, adjustedTimestampSeconds.ToString(CultureInfo.InvariantCulture)));

            return(tokens);
        }
コード例 #2
0
        /// <summary>
        /// Constructs a URI to call for authentication given the target URI provided
        /// </summary>
        /// <param name="callbackUri">The target which the D2L server should return to after authenticating</param>
        /// <returns>The URI for the user to authenticate against</returns>
        private string BuildAuthenticationUriQueryString(Uri callbackUri)
        {
            string callbackUriString = callbackUri.AbsoluteUri;
            string uriHash           = D2LSigner.GetBase64HashString(m_appKey, callbackUriString);
            string result            = APP_ID_PARAMETER + "=" + m_appId;

            result += "&" + APP_KEY_PARAMETER + "=" + uriHash;
            result += "&" + CALLBACK_URL_PARAMETER + "=" + HttpUtility.UrlEncode(callbackUriString);
            return(result);
        }