Method GetTokenAsync unavailable - identityserver4

I´m following the Quickstarts from IdentityServer4. When I implement the "Switching to Hybrid Flow and adding API Access back" tutorial, I found that the method to get the access token in line:
ViewContext.HttpContext.Authentication.GetTokenAsync("access_token")
is not available. Someone knows what method I must to use? Thanks.

The problem was that in my MVC controller I had the using Microsoft.AspNetCore.Authorization;. This library allows use the [Authorize] attribute but has his own HttpContext.Authentication namespace. The solution is add using Microsoft.AspNetCore.Authentication and now I can access to the GetTokenAsync method.

Related

authentication/http headers support in forge.file trigger.io module?

in the official trigger.io docs there seems to be no provision for custom http headers when it comes to the forge.file module. I need this so I can download files behind an http authentication scheme. This seems like an easy thing to add, if support is not already there.
any workarounds? any chance of a quick fix in the next update? I know I could use forge.request instead, but I'd like to keep a local copy (saveURL).
thanks
Unfortunately the file module just uses simple "download url" methods rather than a full HTTP request library, which makes it a fairly big task to add support for custom headers.
I've added a task to our backlog for this, but I don't have a timeframe for it being added.
Currently on iOS you can do basic auth by using urls in the form http://user:password#url.com in case that helps.
Maybe to avoid this you can configure your server differently, or have a proxy server in front that allows you to pass authentication details as get parameters?

How to use google.maps within an asmx web service

I need to calculate distances for some logic within a web service and assume google.maps API is appropriate. Everything I've seen is Jscript and requires a reference to the script in html tags <script>, which does not apply here. A .dll would make things obvious to me, but that does not seem to be available...
How do you access google.maps within a c# .asmx??
You will have to do the same thing that would be done by the JavaScript code you're seeing as examples. You'll want to use the WebClient class or maybe the WebRequest class to do the network I/O, but you've got to send and receive HTTP messages.
"Add Service Reference" won't work, of course.
Note that this problem is not specific to ASMX web services. You would have the exact same issue in a console program or Winforms application.

Has anyone used Enunciate to generate WADL for a RestEasy service?

There are two similar questions asked here and here but no adequate answers are given.
I found that I can use Enunciate to create WADL for a RestEasy service. So I tried it.
In one of my services I have a method mapped to HTTP GET which I am using like below
...
import org.jboss.resteasy.annotations.Form;
...
#GET
#Produces({MediaType.APPLICATION_JSON})
#Transactional(readOnly = true)
public WebServicePageResponse<D> find(#Form WebServicePageRequest<E> wsPageRequest)
{
...
}
Enunciate performs a validation on the service methods before it generates the WADL, and throws this error and fails
"A resource method that is mapped to HTTP GET must not specify an entity parameter."
#Form is a RestEasy specific annotation, while Enunciate can only parse JSR-311 annotations.
Has anyone done something similar? Has anyone successfully used Enunciate to generate documentation for a RestEasy service? Are there any alternatives?
Looks like a great suggestion for a new feature. Tracking it here.
It might be an awkward workaround, but have you tried using the signature override?
The best solution I found to this was to remove #Form annotation and use the individual annotations instead (enter link description hereatleast till Enunciate start supporting this).

Accessing FacesContext in Portal Application

We need to get certain information from PortletRequest in our Portal application. We do that using a utility method inside our Portlet Application. In this Utility method we access FacesContext.getCurrentInstance().getRequest() to get the PortletRequest. We access this Utility method in our DAO layer. We do not have access to request parameter here.
It works sometimes, but at times it gives me NullPointerException. I found a similar thread which explains about this. They have mentioned, if it is part of the same request, then you should get the Context. For me, it is part of the same request, but I'm not getting the context. Can you please help me.
If you are getting a null FaceContext from FacesContext.getCurrentInstance() then no FacesContext has been constructed for this Thread/Request.
Are the failing requests coming through a non-faces entry point? Such as an Event or Resource portlet request? If so there will be no FacesContext created.
Rather than relying on static methods and thread local storage to access data in you DAO you should consider extracting what you need from the PortletRequest, and passing it down your stack. It is bad practice to mix presentation layer artefacts such as the FaceContext or a PortletRequest with your DAO layer.
If your application is deployed in separate WAR/JAR files, it is likely that different classloaders are used. I had a similar problem, when I tried to access the FacesContext inside an hibernate HAR archive on JBOSS5. I came up with a successfull solution using reflection API. Take a look at this.
If you bundle your whole application into one EAR, you might be able to force the use of one classloader for the whole ear, but AFAIK that is application server specific.
Regards

How can I access a REST API through Silverlight (With basic auth)?

I'm trying to access a run-of-the-mill REST API through a silverlight application, but can't seem to get basic authentication to work (using silverlight 4.0).
I'm using a .NET WebClient, and setting the webclient.Credentials with a valid username/password (for the API).
I'm running into two main errors:
System.NotSupportedException: BrowserHttpWebRequest does not support custom credentials.
(this only occurs when I set the webclient.UseDefaulCredentials to false)
and
System.NotImplementedException: This property is not implemented by this class.
at System.Net.WebRequest.set_Credentials(ICredentials value)
(occurs when webclient.UseDefaultCredentials isn't set at all)
what am I missing here? Is basic auth still not supported in Silverlight 4.0?
There is an article about it here http://mark.mymonster.nl/2009/12/02/silverlight-4-credentials-weve-got-it/ and it seems the magic line is:
WebRequest.RegisterPrefix("http://", System.Net.Browser.WebRequestCreator.ClientHttp);
In my case it seems to send the credentials, but I still end up with a 401 error but I just grabbed one of my web servers to try and it may not be configured correctly, but this seems like it should work.
I would also suggest trying the open source library Hammock for REST It provides a very useful wrapper around a lot of modern web calls like REST and oAuth.

Resources