Invalidate Oauth token - oauth

I am trying to invalidate a token but I get the following exception:
+ Headers {X-AspNetMvc-Version: 3.0
xoauth_problem: parameter_absent
xoauth_parameters_absent: oauth_session_handle&oauth_token
Connection: keep-alive
Content-Length: 165
Cache-Control: private
Content-Type: text/html; charset=utf-8
Date: Thu, 16 Aug 2012 20:03:38 GMT
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
} System.Net.WebHeaderCollection
Here is the code:
Uri url = new Uri("https://XXXYYY/OAuth/InvalidateToken");
string oauthHeader = "OAuth oauth_session_handle="AAA3D&",oauth_token="SDSFSDSDF%3D",oauth_consumer_key="5512CONSUMER",oauth_nonce="0000012145o",oauth_signature="QEESIGN99$",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1345141023",oauth_version="1.0"";
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(url);
webReq.Method = WebRequestMethods.Http.Get;
webReq.Headers.Add(HttpRequestHeader.Authorization, oauthHeader);
WebResponse response = webReq.GetResponse();
Please note I do have parameters

Related

MVC 4 WebRequest WebResponse caching

I am trying to disable the caching on on the the pages. The reason - the page in question should display up to date data on each request and the data is coming from external XML feed.
I am using standard HttpWebRequest HttpWebResponse. All is working fine but I am getting some (I believe) caching issues where by querying XML feed URL directly I am getting more up to date data compared to my Controller/View data which uses the same URL.
XML feed URL is appended with random numbers on each request and Caching was disabled in the controller ([OutputCache(NoStore = true, Duration = 0)]) as well as in the ActionResult, which produces the following:
Response
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Expires: -1
Server: Microsoft-IIS/10.0
X-AspNetMvc-Version: 5.1
X-AspNet-Version: 4.0.30319
X-Frame-Options: SAMEORIGIN
X-Powered-By: ASP.NET
X-UA-Compatible: IE=edge
Date: Thu, 04 Aug 2016 13:22:33 GMT
Content-Length: 75285
Request
pretty print
GET /investor-relations/share-price HTTP/1.1
Host: cms.crestnicholson-dev.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: ecos.dt=1470316952533; ASP.NET_SessionId=5lbh4v20kac0boadibjfwedr; IsAgreeToCookiePolicy=true
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
And still outdated/cached data is rendered on the pageā€¦
If someone has any ideas/suggestions, It would be greatly appreciated.
Controller code:
[OutputCache(NoStore = true, Duration = 0)]
public class InvestorRelationsController : Controller
{
public ActionResult SharePrice()
{
Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
Response.Cache.SetValidUntilExpires(false);
Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
return PartialView(GetSharePrice());
}
private SharePriceModel GetSharePrice()
{
try
{
var xml = GetSharePriceXml();
return ParseSharePrice(xml);
}
catch (Exception)
{
return new SharePriceModel() {IsServiceUnavailable = true};
}
}
private SharePriceModel ParseSharePrice(string xml)
{
Guard.ArgumentNotNull(xml, "xml");
var model = new SharePriceModel();
var doc = new XmlDocument();
doc.Load(new StringReader(xml));
var root = doc.DocumentElement;
model.DateLastUpdated = root.SelectSingleNode("Time").InnerText;
model.Price = root.SelectSingleNode("CurrentPrice").InnerText;
model.Change = root.SelectSingleNode("Change").InnerText;
model.ChangePersentage = root.SelectSingleNode("PercentageChange").InnerText;
return model;
}
private string GetSharePriceXml()
{
Uri address = new Uri(SiteConfiguration.SharePriceFeedUrl);
Random random = new Random();
string url = address + "?random=" + random.Next();
// Set a default policy level for the "http:" and "https" schemes.
HttpRequestCachePolicy policy = new HttpRequestCachePolicy(HttpRequestCacheLevel.Default);
HttpWebRequest.DefaultCachePolicy = policy;
HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
// Create the web request
var request = WebRequest.Create(url) as HttpWebRequest;
// Set type to POST
request.CachePolicy = noCachePolicy;
request.KeepAlive = false;
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
request.Headers.Add("Cache-Control", "no-cache");
request.Headers.Add("Cache-Control", "private");
// Get response
using (var response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
using (var reader = new StreamReader(response.GetResponseStream()))
{
// Console application output
return reader.ReadToEnd().Trim();
}
}
}
}

Odata Controller: Content () method behaving unexpected when pass C# object entity as input

I am trying to pass an C# object in Odatacontroler Content method:
var resp = Content(HttpStatusCode.OK, vResult );
Where vResult is a C# object with two fields (List Messaages; bool IsValidEntity) .
At client when I tried getting response bellow unexpected response coming:
Id = 0x00000003, Status = RanToCompletion, Method = "{null}", Result =
"StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content:
System.Net.Http.StringContent, Headers:\r\n{\r\n Pragma: no-cache\r\n
Cache-Control: no-cache\r\n Date: Wed, 06 Jan 2016 07:04:25 GMT\r\n
Server: Microsoft-IIS/7.5\r\n X-AspNet-Version: 4.0.30319\r\n
X-Powered-By: ASP.NET\r\n Content-Type: application/json;
odata.metadata=minimal\r\n Content-Length: 97\r\n}"
For details below can be referenced:
Odata Controller: How to convert Odata response to C# object at client

Making a post request to pastebin returns a 302 - Moved Temporarily response

I am doing a simple post using GM_xmlhttpRequest to post some text to pastebin. This is my code
GM_xmlhttpRequest({
method: "POST",
url: "http://pastebin.com/post.php",
data: "api_dev_key=5c3***********************073a&api_option=paste&api_paste_code="+encodeURI(photo_url)+"&api_user_key=5******************************f&api_paste_name=cornered&api_paste_private=2&api_paste_expire_date=1W",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
onload: function(response) {
alert("posted " + response);
}
});
I am getting no response in the script. To check if the post request itself is working, I used http://requestmaker.com/ and it shows that the POST request is returning a 302 response
Request Headers Sent:
POST /post.php HTTP/1.1
Host: pastebin.com
Accept: */*
Content-Type: application/x-www-form-urlencoded
Content-Length: 152
Response Headers:
HTTP/1.1 302 Moved Temporarily
Date: Wed, 10 Dec 2014 15:27:20 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: __cfduid=d61fd0544ec1b0c284ba908367557bc7f1418225240; expires=Thu, 10-Dec- 15 15:27:20 GMT; path=/; domain=.pastebin.com; HttpOnly
X-Powered-By: PHP/5.5.5
Set-Cookie: cookie_key=1; expires=Wed, 07-Jan-2015 15:27:20 GMT; Max-Age=2419200; path=/; domain=.pastebin.com
Set-Cookie: realuser=1; expires=Thu, 11-Dec-2014 15:27:20 GMT; Max-Age=86400; path=/
location: /index.php?e=2
Vary: Accept-Encoding
Server: cloudflare-nginx
CF-RAY: 196a7749d5c713e9-LAX
Send your request to http://pastebin.com/api/api_post.php instead of http://pastebin.com/post.php.

Coldfusion - Google OAuth2.0 not working in hosted environment on Safari

I am having an issue with the Google OAuth using cfhttp in Safari. It works in my local environment but on our hosted environment everytime I use google oauth, I get the return code below:
Error detail:
string 400 Bad Request
File content:
string { "error" : "invalid_grant", "error_description" : "Code was already redeemed." }
Header:
string HTTP/1.1 400 Bad Request Content-Type: application/json Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: Fri, 01 Jan 1990 00:00:00 GMT Date: Sat, 22 Nov 2014 01:38:30 GMT X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block Server: GSE Alternate-Protocol: 443:quic,p=0.02 Transfer-Encoding: chunked
<cffunction name="getGoogleToken" access="public" output="false">
<cfargument name="Event" type="any">
<cfargument name="code" type="any">
<cfset var rc = Event.getCollection() />
<cfscript>
var postBody = "code=" & UrlEncodedFormat(arguments.code) & "&";
postBody = postBody & "client_id=" & UrlEncodedFormat(rc.googleclientid) & "&";
postBody = postBody & "client_secret=" & UrlEncodedFormat(rc.googleclientsecret) & "&";
postBody = postBody & "redirect_uri=" & UrlEncodedFormat(rc.googlecallback) & "&";
postBody = postBody & "grant_type=authorization_code";
</cfscript>
<cfhttp url="https://accounts.google.com/o/oauth2/token" method="post" result="result" charset="utf-8">
<cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded">
<cfhttpparam type="body" value="#postBody#">
</cfhttp>
<cfdump var="#result#" />
<cfabort>
<cfreturn deserializeJSON(result.filecontent.toString()) />
</cffunction>
"Code was already redeemed." error means that you are trying to use an authorization code that has already been used. for example it call in two functions and therefore twice send a request for access token. Note that the given authorization code can be used only once.

getting boolean or string from ASP.NET Web API via IOS

I can get the value in JSON format with the function:
NSMutableArray *jsonArrayClass = [NSJSONSerialization JSONObjectWithData:data
options:kNilOptions
error:&error];
But i really have no idea how to get the string value or boolean value. we have some validation will return this data type. not JSON.
The raw value shown on Flidder looks like (ID00001 is the return string):
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 07 Apr 2014 17:15:28 GMT
Content-Length: 9
"ID00001"
Try this
[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

Resources