Наследование: IOAuthResponse
Пример #1
0
        /// <summary>
        /// Posts to the OAuth flow with a code retrieved during explicit authentication and attempts to retrieve an access token.
        /// </summary>
        /// <param name="appSecret">Your application's client_secret.</param>
        /// <param name="code">A code retrieved from https://stackexchange.com/oauth, as part of the explicit flow.</param>
        /// <returns>An access token or any raised exceptions wrapped in a response object.</returns>
        public IOAuthResponse RequestAccessToken(string appSecret, string code)
        {
            if (appSecret == null)
            {
                throw new ArgumentNullException("appSecret");
            }
            if (code == null)
            {
                throw new ArgumentNullException("code");
            }
            string endpoint = RequestAccessTokenEndpoint;

            IList <QueryParam> parameters = new List <QueryParam>();

            parameters.Add(new QueryParam(OAuth.AppIdParameter, AppId));
            parameters.Add(new QueryParam(OAuth.AppSecretParameter, appSecret));
            parameters.Add(new QueryParam(OAuth.RedirectUriParameter, RedirectUri));
            parameters.Add(new QueryParam(OAuth.AccessCodeParameter, code));
            string query = string.Join("&", parameters);

            OAuthResponse response = HttpPost <OAuthResponse>(endpoint, query);

            return(response);
        }