0

I'm new to developing rest web services and now, I'm trying to add authenication via this url: http://developers-blog.helloreverb.com/enabling-oauth-with-swagger/

Unfortunately, I'm stuck on the first step, when it says to edit the resource listing, which I believe is the api-docs, right? So, how am I supposed to edit that if its generated by the service and not stored as a file anywhere?

My Swagger version is 1.2

2 Answers 2

1

The link you provided refers to Swagger 1.2 but the latest version is Swagger 2.0

As a starting point, you may consider using editor.swagger.io and reviewing the petstore example, which contains authentication-related setting

Sign up to request clarification or add additional context in comments.

2 Comments

My swagger version is 1.2
If using Swagger Spec 1.2 is a must, then please refer to the Authorization Objects section of the specification.
0

Take a look at the pet store sample from the 1.3.12 tag which was the last version producing Swagger 1.2 - https://github.com/swagger-api/swagger-core/tree/v1.3.12/samples/java-jaxrs.

Specifically, you need to add the definitions to something like your Bootstrap class:

public class Bootstrap extends HttpServlet {
  static {
    // do any additional initialization here, such as set your base path programmatically as such:
    // ConfigFactory.config().setBasePath("http://www.foo.com/");

    ApiInfo info = new ApiInfo(
      "Swagger Sample App",                             /* title */
      "This is a sample server Petstore server.  You can find out more about Swagger " + 
      "at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger.  For this sample, " + 
      "you can use the api key \"special-key\" to test the authorization filters", 
      "http://helloreverb.com/terms/",                  /* TOS URL */
      "[email protected]",                            /* Contact */
      "Apache 2.0",                                     /* license */
      "http://www.apache.org/licenses/LICENSE-2.0.html" /* license URL */
    );

    List<AuthorizationScope> scopes = new ArrayList<AuthorizationScope>();
    scopes.add(new AuthorizationScope("email", "Access to your email address"));
    scopes.add(new AuthorizationScope("pets", "Access to your pets"));

    List<GrantType> grantTypes = new ArrayList<GrantType>();

    ImplicitGrant implicitGrant = new ImplicitGrant(
      new LoginEndpoint("http://petstore.swagger.wordnik.com/oauth/dialog"), 
      "access_code");

    grantTypes.add(implicitGrant);

    AuthorizationType oauth = new OAuthBuilder().scopes(scopes).grantTypes(grantTypes).build();

    ConfigFactory.config().addAuthorization(oauth);
    ConfigFactory.config().setApiInfo(info);
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.