Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Rest Authentication #475

@dhleong

Description

@dhleong

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 setAuthentication or setHttpBasicAuth convenience method. The mix of terminology is annoying, but the relevant Spring HttpHeaders class is HttpAuthentication, so setAuthentication makes 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 RequiresHeader annotation

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 RequiresCookie annotation

setHttpBasicAuth(String username, String password)

  • Stores the header for use in methods with the appropriate RequiresAuthentication annotation

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions