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

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

Activity

  1. pyricau commented on Feb 27, 2013

    @pyricau
    Contributor

    Hi @dhleong

    This looks interesting. I'm not exactly sure about what you are asking here though. What do you need help with ?

  2. dhleong commented on Feb 27, 2013

    @dhleong
    ContributorAuthor

    I'm having trouble building AA into a jar I can use in my project to test
    it in real usage. I've tried various incantations of mvn package and mvn
    install but keep getting various errors--failed tests, or unable to find
    the annotations package, some sort if VerifyError (if I recall correctly)
    etc. It seems to compile if I ignore the tests when I build, but using it
    in the project results in no classes generated.

    Admittedly, I'm new to maven and am unfamiliar with this build process, but
    I'm using the stable AA in another project, and got the code to generate
    successfully in the test harness version of eclipse with the functional
    test project. I just can't seem to get it to cooperate with my actual
    project.

    Should I just open a pull request? I merged some changes to develop into my
    branch that were made after I wrote my I initial implementation, and I'm
    not positive I resolved the conflicts correctly, since I've been having
    these build issues.

    Thanks!
    On Feb 27, 2013 5:34 AM, "Pierre-Yves Ricau" notifications@github.com
    wrote:

    Hi @dhleong https://github.com/dhleong

    This looks interesting. I'm not exactly sure about what you are asking
    here though. What do you need help with ?

    —
    Reply to this email directly or view it on GitHubhttps://github.com//issues/475#issuecomment-14166908
    .

  3. pyricau commented on Feb 27, 2013

    @pyricau
    Contributor

    Well, you shouldn't create a pull request if you are not sure about what your code does and if you cannot build and test.

    You should first focus on getting the thing to build and run, and know what your exact changes are.

    Have you followed these steps ?

  4. dhleong commented on Feb 27, 2013

    @dhleong
    ContributorAuthor

    Yes, I followed those steps to get it to work in the first place, but they
    don't describe how to package it. I mentioned the pull request because I
    thought someone with more experience with the code base might be able to
    glance at it and see something obvious that I'm messing up in the build
    process.

    On Wed, Feb 27, 2013 at 12:03 PM, Pierre-Yves Ricau <
    notifications@github.com> wrote:

    Well, you shouldn't create a pull request if you are not sure about what
    your code does and if you cannot build and test.

    You should first focus on getting the thing to build and run, and know
    what your exact changes are.

    Have you followed these stepshttps://github.com/excilys/androidannotations/wiki/InstallingEnvironment?

    —
    Reply to this email directly or view it on GitHubhttps://github.com//issues/475#issuecomment-14185496
    .

  5. pyricau commented on Feb 28, 2013

    @pyricau
    Contributor

    oh. Packaging is a simple as running mvn clean package in the root folder (here)

  6. dhleong commented on Feb 28, 2013

    @dhleong
    ContributorAuthor

    Right. I tried that and got a bunch of errors saying

    package org.androidannotations.annotations does not exist

    Thanks for your help so far. I may take some time to revisit this over the weekend, perhaps pull out my code and try reintegrating it into a clean branch in case I somehow messed up one of the configuration files.

  7. pyricau commented on Feb 28, 2013

    @pyricau
    Contributor

    Ok :) . If you find these errors again, please post the full stacktrace.

  8. added a commit that references this issue on Jul 12, 2013
  9. DayS commented on Jul 12, 2013

    @DayS
    Contributor

    Merged. I'm leave this issue open until we update the wiki

  10. codebreaker commented on Aug 28, 2013

    @codebreaker

    I'm using 3.0-milestone build and it looks like using @RequiresHeader for a HTTP DELETE is not adding headers.

  11. dhleong commented on Aug 30, 2013

    @dhleong
    ContributorAuthor

    It looks like DELETE, etc. were left out in the cold because they don't typically have an entity. I whipped up some code in my repo at home, but it's probably pretty out of date with the rest of the repo, so I'll need to take some time to pull the changes and submit a pull request. I've been pretty fried from work this past week so I haven't had a chance to get to that just yet....

    If you're in a rush and can build from source, it's pretty straightforward to add in.

  12. DayS commented on Oct 12, 2013

    @DayS
    Contributor

    The two fixes have been merged. I also worked on this part of the wiki but I still have to adjust some things before updating it.

  13. DayS commented on Oct 13, 2013

    @DayS
    Contributor

    Documentation has been updated. Please let me know if you see mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions