Identity Model invalid_client - asp.net

I am just starting to learn about identity model and have been looking at the examples here - https://identitymodel.readthedocs.io/en/latest/client/token.html
I'm looking at the simplest example - Requesting a token using the client_credentials Grant Type - and using the example code I have put together some simple vb.net to test and experiment with.
The problem I am getting is that I only ever get back an invalid_client error message.
I'm sure it is something obvious that I am missing but if someone could point me i the right direction that would be immensely helpful.
Dim request As New ClientCredentialsTokenRequest
request.Address = "https://demo.identityserver.io/connect/token"
request.ClientId = "client"
request.ClientSecret = "secret"
request.Scope = "api1"
Dim client As New HttpClient
Dim response As TokenResponse = Await client.RequestClientCredentialsTokenAsync(request)

As indicated in the reply by #abdusco the correct code should look like
Dim request As New ClientCredentialsTokenRequest
request.Address = "https://demo.identityserver.io/connect/token"
request.ClientId = "m2m"
request.ClientSecret = "secret"
request.Scope = "api"
Dim client As New HttpClient
Dim response As TokenResponse = Await client.RequestClientCredentialsTokenAsync(request)
Thank you for the help.

Related

SagePay RedirectURL failure

Using server integration and .net, I post the original request to SagePay and get the NextURL fine, and so go to the payment pages... step through them OK, but then I get the error:
Server error 5006: Unable to redirect to Vendor's web site. The Vendor failed to provide a RedirectionURL.
HTTP error 500: The request was unsuccessful due to an unexpected condition encountered by the server.
But I am sending a RedirectionURL (though the docs call is RedirectURL, which is somewhat confusing - anyway, I've tried using both. This si what I'm sending back from my NotificatioURL - what's wrong?
Dim sb As New StringBuilder
sb.Append("Status=OK")
sb.Append("&StatusDetail=Fine")
sb.Append("&RedirectURL=https://mydomain.co.uk/sagepay.aspx")
Dim urlTEST As String = "https://test.sagepay.com/gateway/service/vspserver-register.vsp"
Dim urlLIVE As String = "https://live.sagepay.com/gateway/service/vspserver-register.vsp"
Try
Dim data As Byte() = Encoding.UTF8.GetBytes(sb.ToString)
Dim request As WebRequest = WebRequest.Create(urlTEST)
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = data.Length
ServicePointManager.ServerCertificateValidationCallback = AddressOf ValidateRemoteSSLCertificate
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Dim stream = request.GetRequestStream()
stream.Write(data, 0, data.Length)
stream.Close()
Dim response As WebResponse = request.GetResponse()
response.Close()
Catch ex As Exception
'log error
End Try
Update: I gather this POST (unlike the initial one with the basket info) requires that the data be sent plain text key-value pairs separated by CrLf's, so I amended this to
Dim sb As New StringBuilder
sb.AppendLine("Status=OK")
sb.AppendLine("StatusDetail=Fine")
sb.Append("RedirectURL=https://mydomain.co.uk/sagepay.aspx")
but it still fails with the same errors. I also tried using, instead of the WebRequst class, the simpler:
Dim client As WebClient = New WebClient()
Dim reply As String = client.UploadString(urlTEST, sb.ToString)
But still no joy. Also tried changing the request.ContentType to "text/plain", but nope.
Come on, someone, please - this si basic to the their operations, someone must have done it....
Blimey - it never pays to be clever. This script doesn't require WebRequest or anything, just write to the simple Response object. Sigh.. as Linus said ....

Basic Authentication with asmx web service

I'm trying to implement Basic Authorization for an ASMXweb service. I created the client as a service reference in VS2015. I'm using code in Asmx web service basic authentication as an example.
I'm entering login info in ClientCredentials as below
Dim svc As New WebServiceSoapClient()
svc.ClientCredentials.UserName.UserName = "userId"
svc.ClientCredentials.UserName.Password = "i2awTieS0mdO"
My problem is that in the Authorization HttpModule in the web service, these credentials are not being passed to module. Is there an alternate way to do this?
I found the parts answer at How to add HTTP Header to SOAP Client. I had to combine a couple of answers on that page to get it to work.
Dim svc As New WebServiceSoapClient()
Dim responseService As SoapResponseObject
Using (new OperationContextScope(svc.InnerChannel))
Dim auth = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes("userId:i2awTieS0mdO"))
Dim requestMessage = New HttpRequestMessageProperty()
requestMessage.Headers("Authorization") = auth
OperationContext.Current.OutgoingMessageProperties(HttpRequestMessageProperty.Name) = requestMessage
dim aMessageHeader = MessageHeader.CreateHeader("Authorization", "http://tempuri.org", auth)
OperationContext.Current.OutgoingMessageHeaders.Add(aMessageHeader)
responseService = svc.ListDistricts(requestService)
End Using
One key thing to be aware of is that the soap client call has to be inside the Using statement. In the above code, this is the next to last line.

WooCommerce REST API The remote server returned an error: (401) Unauthorized VB.NET

My site (https://www.trs.is) recently switched to https and now I am getting an Unauthorized error when I try to get all products from my WooCommerce store. I have tried many things with the WebClient() to use basic authentication but I always get this error.
I have also tested this with Postman from Google with basic auth and using the client key and client secret but the error is always the same.
Scratching my head here and after hours of searching I can not see why the this is happening.
Here is my latest code (actual client keys are removed)
Dim url As String = "https://www.trs.is/wc-api/v3/products"
'Dim client As New WebClient()
Dim userName As [String] = "myclientkey"
Dim passWord As [String] = "myclientsecret"
'client.Credentials = New System.Net.NetworkCredential(userName, passWord)
Dim credentials As String = Convert.ToBase64String(Encoding.ASCII.GetBytes(userName + ":" + passWord))
wc.Headers(HttpRequestHeader.Authorization) = Convert.ToString("Basic") & credentials
Dim result = wc.DownloadString(url)
Any help guys ?
Try using wc.UseDefaultCredentials = True and post your API keys instead.

How to redirect to home page of Pentaho after basic authentication in .NET?

I try to use basic authentication in VB.NET side to login Pentaho
I use the default account of Pentaho for testing
username: joe
password: password
I have following code in VB.NET for basic authentication to Pentaho
Dim request = WebRequest.Create("http://x.x.x.x:8080/pentaho/Home")
Dim authInfo As String = Convert.ToString(userName) & ":" & Convert.ToString(userPassword)
authInfo = Convert.ToBase64String(Encoding.[Default].GetBytes(authInfo))
request.Headers("Authorization") = "Basic " & authInfo
Dim response As WebResponse = request.GetResponse()
After ran the request.GetResponse() can get the successful result. So I think the Pentaho login and authentication successfully
But when I go to http://x.x.x.x:8080/pentaho/Home Pentaho still prompt to Login Pageā€¦
Do You know What wrong of my code?
Thanks in advance!!
Not sure what you're trying to do here. Where are you going to pentaho/Home. In your code ?
If you want to programatically call a certain URL in Pentaho, it's probably easier to append the credentials to the query string.
You can use Basic Authentication method, I already answered this question in bellow post.
enter link description here
Eg-
WebClient webClient = new System.Net.WebClient();
Uri uri = new Uri("http://serverDomain:8080/pentaho/Home");
//Give user name and password here
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes("username:password");
var encodedString = System.Convert.ToBase64String(plainTextBytes);
webClient.Headers["Authorization"] = "Basic " + encodedString;
webClient.Encoding = Encoding.UTF8;
App.WindowManager.ConsoleWrite(uri.ToString());
webClient.UploadStringAsync(uri, "POST", "");

Exception thrown when using GData .NET Analytics API

I am facing an issue while trying to fetch data from GoogleAnalytics API on piece of code that has been working well just a couple of days ago.
For this I am referencing the following DLL's:
Google.GData.Analytics.dll
Google.GData.Client.dll
Google.GData.Extensions.dll
And I am using the following code:
Dim visits As String = String.Empty
Dim username As String = "myuser#mydomain.com"
Dim pass As String = "mypassword"
Const dataFeedUrl As String = "https://www.google.com/analytics/feeds/data"
Dim query As AccountQuery = New AccountQuery()
Dim service As AnalyticsService = New AnalyticsService("MyWebAnalyticsService")
service.setUserCredentials(username, pass)
Dim accountFeed As AccountFeed = service.Query(query) ''----------> Exception thrown in this line: GDataRequestException Execution of request failed: https://www.google.com/analytics/feeds/accounts/default
I thought it had to do with a blocking to the account I was using but it wasn't the case because I verified registering the site for another analytics account and is still not working.
This code has been working flawlessly as I've said but all of a sudden has stopped doing so yesterday.
Could you please help me figuring out what's wrong?. Maybe the way the user credentials are set has changed and I am missing something.
Thank you very much for your help.
'----Update----
I managed to make it work and now I can query the visits for a desired domain. The code goes as follows:
Dim visits As String = String.Empty
Dim username As String = "myuser#mydomain.com"
Dim pass As String = "mypassword"
'Follow the instructions on https://developers.google.com/analytics/resources/articles/gdata-migration-guide (Create a Project in the Google APIs Console) to generate your key
'Once you have it set it as part of the querystring to request our GA service
Dim gkey As String = "key=yourkeystring"
'Set the new URI to retrieve the feed data and append it the generated key
Dim dataFeedUrl As String = "https://www.google.com/analytics/feeds/data?" & gkey
'Create and authenticate on our service instance
Dim service As AnalyticsService = New AnalyticsService("MyAnaliticsService")
service.setUserCredentials(username, pass)
'Use the profile id for the account you want to get ths visits from, you can find it
'logging in your analytics account, select the desired domain on your list (blue link)
click on the administrator button and on the profiles tab find the profile
'configuration subtab, right there you will find the profile id in this case the eight characters long id 12345678
Dim query1 As DataQuery = New DataQuery(dataFeedUrl)
With query1
.Ids = "ga:12345678"
.Metrics = "ga:visits"
.Sort = "ga:visits"
.GAStartDate = DateTime.Now.AddMonths(-1).AddDays(-2).ToString("yyyy-MM-dd")
.GAEndDate = DateTime.Now.ToString("yyyy-MM-dd")
.StartIndex = 1
End With
'Use the generated datafeed based on the former query to get the visits
Dim dataFeedVisits As DataFeed = service.Query(query1)
For Each entry As DataEntry In dataFeedVisits.Entries
Dim st As String = entry.Title.Text
Dim ss As String = entry.Metrics(0).Value
visits = ss
Next
I have the same problem and it looks like google recently shut down the feed. It is answered in another post. Issue com.google.gdata.util.ResourceNotFoundException: Not Found with Google Analytic
Please make sure you registered your project in the APIs Console and you are sending the API Key with your requests.
If that is not the issue, inspecting the inner exception will give you more details about the error. As an alternative, you can use Fiddler to capture the HTTP request and the response. The latter will include a more descriptive error message.

Resources