public void ProcessAuthorizationCode(string code, OAuthApplication application, OAuthToken token)
        {
            var tokenClient   = new TokenClient(tokenUrl, application.ClientID, application.ClientSecret, AuthenticationStyle.PostValues);
            var tokenResponse = tokenClient.RequestAuthorizationCodeAsync(code, AuthenticationHandler.ReturnUrl).Result;

            FillTokenFromTokenResponse(tokenResponse, token);
        }
        public void RefreshAccessToken(OAuthToken token, OAuthApplication oAuthApplication)
        {
            var refreshToken  = token.RefreshToken;
            var client        = new TokenClient(tokenUrl, oAuthApplication.ClientID, oAuthApplication.ClientSecret, AuthenticationStyle.PostValues);
            var tokenResponse = client.RequestRefreshTokenAsync(refreshToken).Result;

            if (!tokenResponse.IsError)
            {
                FillTokenFromTokenResponse(tokenResponse, token);
                return;
            }
            string error             = tokenResponse.Error;
            string error_description = "";

            try{
                error_description = (((Newtonsoft.Json.Linq.JValue)tokenResponse.Json["error_description"]).Value).ToString();
            }catch (Exception) {}

            Exceptions.VATAPIInvalidToken e = new Exceptions.VATAPIInvalidToken(Model.error.IMPOSSIBLE_TO_REFRESH_TOKEN);
            e.Data.Add("AccessToken", token.AccessToken);
            e.Data.Add("RefreshToken", token.RefreshToken);
            e.Data.Add("Raw", tokenResponse.Raw);

            throw e;
        }
Exemplo n.º 3
0
        public VATApi(string UrlSite, OAuthApplication Application, OAuthToken Token, string VRN, UpdateOAuthTokenDelegate UpdateOAuthToken = null)
        {
            application      = Application;
            token            = Token;
            urlSite          = UrlSite;
            updateOAuthToken = UpdateOAuthToken;
            setVRN(VRN);

            ApplicationProcessor = new MTDApplicationProcessor(UrlSite);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Method to get OAuth Server's app information
        /// </summary>
        /// <param name="refreshToken"></param>
        /// <returns>Oauth</returns>
        public OAuthApplication ExternalLoginInformation(string refreshToken)
        {
            var clientId           = _envVariableRepository.PromactOAuthClientId;
            var clientSecret       = _envVariableRepository.PromactOAuthClientSecret;
            OAuthApplication oAuth = new OAuthApplication();

            oAuth.ClientId     = clientId;
            oAuth.ClientSecret = clientSecret;
            oAuth.RefreshToken = refreshToken;
            oAuth.ReturnUrl    = _stringConstant.ClientReturnUrl;
            return(oAuth);
        }
        public void SignIn(OAuthApplication oAuthApplication, ref OAuthToken token)
        {
            var request = new AuthorizeRequest(authorizationUrl);
            var url     = request.CreateAuthorizeUrl(
                clientId: oAuthApplication.ClientID,
                responseType: OidcConstants.ResponseTypes.Code,
                scope: _scope,
                state: oAuthApplication.ApplicationID.ToString(),
                redirectUri: AuthenticationHandler.ReturnUrl);

            throw new PXRedirectToUrlException(url, PXBaseRedirectException.WindowMode.InlineWindow, "Authenticate");
        }
        public bool IsSignedIn(OAuthApplication application, OAuthToken token)
        {
            if (application == null || token == null)
            {
                return(false);
            }

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, isSignedUrl);

            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(_isSignedAcceptHeader));
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);

            var httpClient = new HttpClient();
            var response   = httpClient.SendAsync(request).Result;

            return(response?.StatusCode == HttpStatusCode.OK);
        }
 public string ResourceHtml(OAuthToken token, OAuthResource resource, OAuthApplication application)
 {
     return(string.Empty);
 }
 public Task <IEnumerable <Resource> > GetResources(OAuthToken token, OAuthApplication application)
 {
     return(Task.FromResult(Enumerable.Empty <Resource>()));
 }