ServiceStack client get generated URL - oauth

Is it possible to access the URL a service call will use before calling the service using any of the ServiceClientBase child classes?
I need to fully resolve the url before making the service call so that the URL can be included into the OAuth authorization signature.

Use the IReturn extension method ToUrl with appropriate HTTP method and format strings.
Example: request.ToUrl("POST", "json") where request implements IReturn.

Not currently, For reference here's the source code for ServiceClientBase. If it helps, you can add a pull-request to make GetUrl overridable and protected, that way it can be accessed by sub classes.

Related

How to call different methods in a controller in OData

I am using web api 2.2 odata v4.0. I have a controller which has 3 methods.
For example GetA(), GetB() and GetC(). Which code should I use so that I will be able to call individual methods from the url ?
Also, how can I call a method GetA()? - as Get() is the default method that is being called in ODataController.
I used the code,
ODataRoute route = config.Routes.MapODataServiceRoute("odata", "odata",GetModel());
route.MapODataRouteAttributes(config); // This line threw an error sowing route does not have the method
MapODataRouteAttributes()
Please suggest me the solution.
Thanks
What do you need GetA(), GetB() and GetC() to do ? Are they for getting specific properties A, B and C? If so, you can take a look at the ODAtaAttributeRoutingSample. And if you want to know more about Web API OData, you can take a look at Sample Service implemented with Web API which is a complete project.
You have to work with the Action Attributes to specify other functions then those following the default rules.
routing with attributes

IBMSBT XPages custom endpoint Callback_uri vs redirect_uri

I'm trying to use the sbt in xpages with a custom endpoint i.e a new one defined in faces config using the class com.ibm.sbt.services.endpoints.OAuth2Endpoint
The authorisation url it generates is in the format of
&client_id=xx&callback_uri=xxx
however the api i'm trying to use expects a parameter of redirect_uri
Looking at the spec for OAuth2 it appears that the convention is to use redirect_uri rather than callback_uri.
Is there a different end point class I can use which would use redirect_uri instead for the auth handler?
NB: I've searched the source code and "OAUTH2_REDIRECT_URI" isn't used anywhere so I guess not, which makes me think I've misunderstood how to use it
Thanks!
I had a similar issue for our Basecamp demo application for IBM Connect 2014.
I have inherited a new endpoint and handler for this purpose.
In the handler class I had to rewrite getAuthorizationNetworkUrl() and getAccessTokenForAuthorizedUser() methods to change those url parameters.
Overriding these methods might not be safe for the future of course. Instead, you might get the original URL and do some string operations to change desired parameters.
#Override
public String getAuthorizationNetworkUrl() {
String newUrl=super();
// Do string operations
return newUrl;
}
Checking if anything changed for the new version of SBT would be needed. I hope it helps.
You can use the SmartCloudOAuth2Endpoint, instead of the plain oauth2 endpoint. This endpoint is a custom endpoint for SmartCloud which uses redirect_uri
https://github.com/OpenNTF/SocialSDK/blob/cd373c78971bb31e1902f177eddcb33d029ae474/sdk/com.ibm.sbt.core/src/main/java/com/ibm/sbt/services/endpoints/SmartCloudOAuth2Endpoint.java

How do I access UrlMapping variables in grails from a filter?

I'm using Grails 2.1.5 and the Spring Security Core plugin.
I've overridden the WebSecurityExpressionRoot to add 2 signatures of a hasPermission method to the web expression paradigm.
This method delegates to classes by name in the applicationContext calling them with the request as an argument and an arbitrary string to provide further details if any are ever required.
In my delegate class I need to be able to access the parameters to assess whether or not the user may access the requested resource and this is fine but the request does not yet contain the variables defined from the UrlMappings.
I have tried acquiring the grailsUrlMappingsHolder from the applicationContext but when I call it's match method with a valid uri I get nothing.
I'm running out of time and may have to parse the request.getRequestURI() myself to try to infer the id if no request parameters are valid but this will not get urls mapped where the id is not last.
I really hate to re-invent the wheel here and I hate to miss out on using the UrlMappings to their fullest potential but the variables they define (in my circumstance) aren't available until I'm in the controller.
Take a look at what I do in AnnotationFilterInvocationDefinition - there's a bit of setup that you need to do: https://github.com/grails-plugins/grails-spring-security-core/blob/master/src/java/grails/plugin/springsecurity/web/access/intercept/AnnotationFilterInvocationDefinition.java

How get URL in CDI inteceptor for Jesey method call?

I am writing CDI Intercepter for Jersey method. Can I receive URL without adding argument with #Context annotation into Jersey method?
In JFS there is static method in FaseContext that can help to get Request for for current Thread (and I can get URL from it):
FaseContext.getCurrentInstance().getExternalContext().getRequest()
Is there some thing similar in Jersey?
You could create a request listener and create a new thread local, or create a producer for it.

Request object or current url (url_for) access inside classes in lib

I'm trying to get a string of the current URL (either from the request object or a call to url_for) inside a class I wrote that resides in my projects lib directory. How do I do this? I tried to
request.url
and the request object is not accessible from within my class.
The request.url is only accessible from inside a controller. I would suggest that the url is a parameter you hand down to your class (at construction-time or when calling the method). This will keep the concerns nicely separated.
Hope this helps.

Resources