-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Rest Authentication #475
Description
Just discovered this the other day and I have to say I'm very excited by the possibilities! I thought I'd play with it for a little project I'm working on that talks to some Google APIs, but found that its authentication stuff was not as convenient as some of the others. So, I thought I'd see if I could come up with something myself. I have a fairly complete implementation (lacking some validation, I think) in a branch on my fork, but am having some difficulties figuring out how to build the jars for use in my project.
I managed to get the APIs to build and the dev Eclipse environment works to generate the code, but if I could get help building (possibly we can put together a Wiki page on it) then I can include it in my API project and do some testing, and open a pull request.
Below are my added annotations and methods.
New Annotations:
@RequiresHeader
- Accepts a string which is the name of a header, or a string[] which contains header names
@RequiresCookie
- Convenience form of RequiresHeader which allows the specification of specific cookie names within the Cookie header, to avoid sending unnecessary cookies.
@RequiresCookieInUrl
- Special annotation which pulls a set cookie from the internal store (either initialized by @SetsCookie or setCookie) and interpolates it into the method's URL. Google Play Music's API does this for some reason in some methods.
@RequiresAuthentication
- Convenience form of RequiresHeader which requires some form of authentication, for the "Authorization" field. This can be set using either
setAuthenticationorsetHttpBasicAuthconvenience method. The mix of terminology is annoying, but the relevant Spring HttpHeaders class is HttpAuthentication, sosetAuthenticationmakes more sense
@SetsCookie
- Indicates that the response of this method sets some cookies that we want to use via setCookie. Accepts a string which is the name of such a cookie, or a
String[]with cookie names
New Interface methods (ala setRootUrl):
setHeader(String name, String value)
- Stores the header for use in methods with the appropriate
RequiresHeaderannotation
setAuthentication(HttpAuthentication value)
- Allows setting whatever type of authentication you want
setCookie(String name, String value)
- Stores the cookie for use in methods with the appropriate
RequiresCookieannotation
setHttpBasicAuth(String username, String password)
- Stores the header for use in methods with the appropriate
RequiresAuthenticationannotation
getCookie(String name)
- Get the value of the cookie with given name. Useful if you want to persist the value of a cookie returned by a method annotated with
@SetsCookie