示例#1
0
        public ActionResult GenerateAuthTokenFromCode(string code, long state)
        {
            OAuthResponse response = null;
            ViewResult    result   = new ViewResult();

            try
            {
                OAuth2Api oAuth = new OAuth2Api();
                response = oAuth.ExchangeCodeForAccessToken(OAuthEnvironment.PRODUCTION, code);
                authorizationManager.SetEbayAuth(response.AccessToken, response.RefreshToken, state);
                result.StatusCode = StatusCodes.Status200OK;
                result.ViewName   = "AuthSuccess";
                return(result);
            }
            catch (NotAuthorizedException ex)
            {
                telemetryClient.TrackException(ex, new Dictionary <string, string> {
                    { "ErrorMessage", ex.Message }
                });
            }
            catch (Exception ex)
            {
                telemetryClient.TrackException(ex, new Dictionary <string, string> {
                    { "ErrorMessage", response?.ErrorMessage }
                });
            }
            result.StatusCode = StatusCodes.Status500InternalServerError;
            result.ViewName   = "AuthError";
            return(result);
        }