With reference from this URI:
http://developer.okta.com/docs/api/resources/oidc.html#parameter-details
I have tried using the /authorize endpoint but I am not getting a token back in the result from Okta, I always get the result as:
404 - Page Not Found
The page you are looking for can't be found. Please go to your applications page and try again.
Can anyone help me on this? Sent email to Okta developer but I'm not getting a reply.
var url = "https://xxx-admin.okta.com/oauth2/v1/authorize";
//string urlParams =
// string.Format("response_type={0}&client_id={1}&redirect_uri={2}&scope={3},state={4},nonce={5}", "code",
// "xxxxxx", redirecturl, "email", "email", );
var urlParameters =
$"?idp={"okta"}&response_type={"id_token"}&client_id={"xxxxx"}&redirect_uri={redirecturl}" +
$"&scope={"openid profile email address"}&response_mode={"form_post"}&state={"email"}&nonce={"nonce"}";
string redirecturl = "http://localhost/";
//grant_type,code,refresh_token,scope,redirect_uri,client_id,client_secret
var urlParameters = $"?grant_type={"password"}&code={""}&refresh_token={""}&redirect_uri={redirecturl}&" +
$"client_id=xxxxx&client_secret=yyyyyy";
var url = "https://xxxx-admin.okta.com/oauth2/v1/token";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url+ urlParameters);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
var strRequest= string.Empty;
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();
return strResponse.ToString();
Looks like you're doing a POST for your method. I think it should be a GET.
Related
Pretty much a noob here, having issues here with a Post Request in C#. I am returning the server response to webBrowser Control, and no matter what I try, I just get the login page returned with no form values posted. Any help here would be greatly appreciated!
Login Page: "https://www.carrier411.com/".
URL example that I want to return:(You have to be logged in to view)
"https://www.carrier411.com/manager/companydetail.cfm?docket=MC1114638"
var username = "******"; var password = "******";
string url = "https://www.carrier411.com/manager/companydetail.cfm?docket=MC1073504";
string postData = System.Convert.ToBase64String(Encoding.UTF8.GetBytes(userName + ":" + passWord));
var httpRequest = (HttpWebRequest)WebRequest.Create(url);
httpRequest.Method = "POST";
httpRequest.ContentType = "text/html";
httpRequest.Headers.Add("Authorization", "Basic " + postData);
httpRequest.Accept = #"text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8";
using (var streamWriter = new StreamWriter(httpRequest.GetRequestStream()))
{streamWriter.Write(postData);}
var httpResponse = (HttpWebResponse)httpRequest.GetResponse();
var streamReader = new StreamReader(httpResponse.GetResponseStream());
string result = streamReader.ReadToEnd().ToString();
webBrowser1.DocumentText = result;
I'm using Xero with c# winforms. Xero released a new topic OAuth2.0 and they are providing sample only for web applications. But I didn't get authorization code. I'm getting an html page as response not the authorization code. Can anyone help me? Thanks for the help in advance.
Here is my current code for getting authorization code:
string XeroUrl = "login.xero.com/identity/connect/authorize?response_type=code&client_id=xxxxxxxxxxxx&redirect_uri=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
string ScopeLimit = "openid profile email accounting.transactions&state=123";
string URL = "https://" + XeroUrl + "&scope=" + ScopeLimit;
try {
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(URL);
webRequest.AllowAutoRedirect = true;
webRequest.Method = WebRequestMethods.Http.Get;
webRequest.UseDefaultCredentials = false;
webRequest.PreAuthenticate = false;
HttpWebResponse response = null;
response = (HttpWebResponse)webRequest.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string output = reader.ReadToEnd();
}
Here is the code that I am using:
public static void FetchXML()
{
_url = new Uri("http://api.tumblr.com/v2/blog/" + _username + ".tumblr.com/likes?api_key=REc3Z6l4ZYss11a8lX6KKje0X8Hsi9U77SyaPbQrOBBCGJGA6D");
var client = new RestClient();
client.Authority = _url.ToString();
var request = new RestRequest();
request.AddParameter("limit", "20");
request.AddParameter("offset", _offset.ToString());
var response = client.Request(request);
var content = response.Content.ToString();
var parsedResponse = JsonParser.FromJson(content);
}
If I take the Uri value and paste it into my browser (using a valid Tumblr username) I'm getting the correct Json, but in my application the content of response is:
"{\"meta\":{\"status\":401,\"msg\":\"Unauthorized\"},\"response\":[]}"
Anyone have any idea why this is? According to the Tumblr API
retrieving likes should only need the API key, which I am providing.
Hi you can use the below code to get the response.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "GET";
request.ContentType = "Application/json";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream receive = response.GetResponseStream();
StreamReader reader = new StreamReader(receive, Encoding.UTF8);
string respond = reader.ReadToEnd();
like the tittle says, I was trying to make a request via post to some page. First using google developer tool, to check parameters for request, and I can figure out this (I am not completly sure if I put all correct parameters in my post string - check images for more information). I found many examples around www but no one works with this and I don't know what is wrong, I will aprecciate like always a bit help :).
Request Headers
Form Data
This is my code:
string email = "xxxxx";
string password = "xxxxx";
string LOGIN_URL = "https://intranet.cibertec.edu.pe/LoginBolsa/LoginBolsaCIB.aspx";
CookieContainer cookies = new CookieContainer();
HttpWebRequest webRequest = WebRequest.Create(LOGIN_URL) as HttpWebRequest;
webRequest.CookieContainer = cookies;
StreamReader responseReader = new StreamReader(
webRequest.GetResponse().GetResponseStream()
);
string responseData = responseReader.ReadToEnd();
responseReader.Close();
string postString = string.Format("ctl00$ContentPlaceHolder1$Login1$UserName={0}&ctl00$ContentPlaceHolder1$Login1$Password={1}&ctl00$ContentPlaceHolder1$Login1$LoginButton={2}&hdnOrigen={3}&hdnLinea={4}&Pagina_Principal={5}", email, password, "Ingresar", "bolsa", "I", "LoginBolsaCIB.aspx");
webRequest = WebRequest.Create(LOGIN_URL) as HttpWebRequest;
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.CookieContainer = cookies;
StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream());
requestWriter.Write(postString);
requestWriter.Close();
responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());
responseData = responseReader.ReadToEnd();
responseReader.Close();
Response.Write(responseData);
It's because a missing __ViewState param. This params which is hidden form field is needed to attach for every Request.
int start = responseData.IndexOf("value=\"", responseData.IndexOf("name=\"__VIEWSTATE\""));
int end = responseData.IndexOf("/>", start);
string viewState = responseData.Substring(start + 7, end - start - 9);
string postString = string.Format("ctl00$ContentPlaceHolder1$Login1$UserName={0}&ctl00$ContentPlaceHolder1$Login1$Password={1}&ctl00$ContentPlaceHolder1$Login1$LoginButton={2}&hdnOrigen={3}&hdnLinea={4}&Pagina_Principal={5}", email, password, "Ingresar", "bolsa", "I", "LoginBolsaCIB.aspx");
postString += String.Concat("&__VIEWSTATE=", viewState);
I am using the following code on Page_Load of facebook_login page in asp.net web application. After redirecting this url I have got the accesstoken in url but when I try to access this current url via HttpContext.Current.Request.Url.AbsoluteUri it gave the url of app where it is published not the url which is currently in window.
How can I access this access token or userdetails?
var uriParams = new Dictionary<string, string>() {
{"client_id", facebookAppId},
{"response_type", "token"},
{"scope", "user_about_me, read_stream, email"},
{"redirect_uri", "http://apps.facebook.com/appNameHere/"}
};
StringBuilder urlBuilder = new StringBuilder();
foreach (var current in uriParams)
{
if (urlBuilder.Length > 0)
{
urlBuilder.Append("&");
}
var encoded = HttpUtility.UrlEncode(current.Value);
urlBuilder.AppendFormat("{0}={1}", current.Key, encoded);
}
var loginUrl = "http://www.facebook.com/dialog/oauth?" + urlBuilder.ToString();
Response.Redirect(loginUrl);
In Facebook you can set call back url value which should point to your web application. So once you make request to http://www.facebook.com/dialog/oauth and after successfully login Facebook redirect to Callback Url (which is your web application).
Then you have to make call to url : https://graph.facebook.com/oauth/access_token something like this:
StringBuilder uri = new StringBuilder();
uri.Append("https://graph.facebook.com/oauth/access_token?");
uri.Append("client_id=" + ClientKey + "&");
uri.Append("redirect_uri=" + Curl + "&");
uri.Append("scope=offline_access&");
uri.Append("client_secret=" + ClientSecret + "&");
uri.Append("code=" + OAuthCode);
HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);
req.Headers.Add("Authorization", String.Empty);
req.Method = "POST";
req.ServicePoint.Expect100Continue = false;
req.ContentLength = 0;
req.ContentType = "application/x-www-form-urlencoded";
HttpWebResponse resp;
try
{
resp = (HttpWebResponse)req.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
string result = sr.ReadToEnd().Trim();
string[] resultCollection = Regex.Split(result, "&");
string access_token = Regex.Split(resultCollection[0], "=")[1];//This is the access token
//which you want and you can save it to database or some where for further use.
}
catch (WebException ex)
{
resp = (HttpWebResponse)ex.Response;
//pass on the exception
throw ex;
}
UPDATE :
OAuthCode you can get like this, it is available when after successfully login FB redirect to your web app page
OAuthCode = Request.Params["code"];
Header you can pass empty like String.Empty