Search in sources :

Example 1 with OAuth2Definition

use of io.swagger.models.auth.OAuth2Definition in project swagger-core by swagger-api.

the class AuthSerializationTest method testImplicitAuth.

@Test(description = "it should convert serialize an oauth2 implicit flow model")
public void testImplicitAuth() throws IOException {
    final OAuth2Definition auth = new OAuth2Definition().implicit("http://foo.com/authorization");
    final String json = "{\"type\":\"oauth2\",\"authorizationUrl\":\"http://foo.com/authorization\",\"flow\":\"implicit\"}";
    SerializationMatchers.assertEqualsToJson(auth, json);
}
Also used : OAuth2Definition(io.swagger.models.auth.OAuth2Definition) Test(org.testng.annotations.Test)

Example 2 with OAuth2Definition

use of io.swagger.models.auth.OAuth2Definition in project swagger-core by swagger-api.

the class AuthSerializationTest method testPasswordAuth.

@Test(description = "it should convert serialize an oauth2 password flow model")
public void testPasswordAuth() throws IOException {
    final OAuth2Definition auth = new OAuth2Definition().password("http://foo.com/token");
    final String json = "{\"type\":\"oauth2\",\"tokenUrl\":\"http://foo.com/token\",\"flow\":\"password\"}";
    SerializationMatchers.assertEqualsToJson(auth, json);
}
Also used : OAuth2Definition(io.swagger.models.auth.OAuth2Definition) Test(org.testng.annotations.Test)

Example 3 with OAuth2Definition

use of io.swagger.models.auth.OAuth2Definition in project swagger-core by swagger-api.

the class AuthSerializationTest method testImplicitWithScopes.

@Test(description = "it should convert serialize an oauth2 implicit flow model with scopes")
public void testImplicitWithScopes() throws IOException {
    final OAuth2Definition auth = new OAuth2Definition().implicit("http://foo.com/authorization").scope("email", "read your email");
    final String json = "{\n" + "   \"type\":\"oauth2\",\n" + "   \"authorizationUrl\":\"http://foo.com/authorization\",\n" + "   \"flow\":\"implicit\",\n" + "   \"scopes\":{\n" + "      \"email\":\"read your email\"\n" + "   }\n" + "}";
    SerializationMatchers.assertEqualsToJson(auth, json);
}
Also used : OAuth2Definition(io.swagger.models.auth.OAuth2Definition) Test(org.testng.annotations.Test)

Example 4 with OAuth2Definition

use of io.swagger.models.auth.OAuth2Definition in project ORCID-Source by ORCID.

the class PublicSwaggerResource method scan.

/**
     * Scan the classes and add in the OAuth information
     * 
     */
@Override
protected synchronized Swagger scan(Application app) {
    // tell swagger to pick up our jaxb annotations
    Json.mapper().registerModule(new JaxbAnnotationModule());
    Swagger s = super.scan(app);
    OAuth2Definition oauthTwoLegs = new OAuth2Definition();
    oauthTwoLegs.application(this.tokenEndPoint);
    oauthTwoLegs.scope(ScopePathType.READ_PUBLIC.value(), "Read Public record");
    s.securityDefinition("orcid_two_legs", oauthTwoLegs);
    return s;
}
Also used : JaxbAnnotationModule(com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule) Swagger(io.swagger.models.Swagger) OAuth2Definition(io.swagger.models.auth.OAuth2Definition)

Example 5 with OAuth2Definition

use of io.swagger.models.auth.OAuth2Definition in project swagger-core by swagger-api.

the class SecurityDefinitionTest method createModelWithSecurityRequirements.

@Test(description = "it should create a model with security requirements")
public void createModelWithSecurityRequirements() throws IOException {
    final Model personModel = ModelConverters.getInstance().read(Person.class).get("Person");
    final Model errorModel = ModelConverters.getInstance().read(Error.class).get("Error");
    final Info info = new Info().version("1.0.0").title("Swagger Petstore");
    final Contact contact = new Contact().name("Swagger API Team").email("foo@bar.baz").url("http://swagger.io");
    info.setContact(contact);
    final Swagger swagger = new Swagger().info(info).host("petstore.swagger.io").scheme(Scheme.HTTP).consumes("application/json").produces("application/json").model("Person", personModel).model("Error", errorModel);
    swagger.securityDefinition("githubAccessCode", new OAuth2Definition().accessCode("http://foo.com/accessCode", "http://foo.com/tokenUrl").scope("user:email", "Grants read access to a user’s email addresses."));
    final Operation get = new Operation().produces("application/json").summary("finds pets in the system").description("a longer description").tag("Pet Operations").operationId("get pet by id");
    get.parameter(new QueryParameter().name("tags").description("tags to filter by").required(false).property(new StringProperty()));
    get.parameter(new PathParameter().name("petId").description("pet to fetch").property(new LongProperty()));
    final Response response = new Response().description("pets returned").schema(new RefProperty().asDefault("Person"));
    final Response errorResponse = new Response().description("error response").schema(new RefProperty().asDefault("Error"));
    get.response(200, response).defaultResponse(errorResponse).security(new SecurityRequirement("internal_oauth2").scope("user:email")).security(new SecurityRequirement("api_key"));
    swagger.path("/pets", new Path().get(get));
    final String json = ResourceUtils.loadClassResource(getClass(), "ModelWithSecurityRequirements.json");
    SerializationMatchers.assertEqualsToJson(swagger, json);
}
Also used : Path(io.swagger.models.Path) QueryParameter(io.swagger.models.parameters.QueryParameter) OAuth2Definition(io.swagger.models.auth.OAuth2Definition) Error(io.swagger.models.Error) StringProperty(io.swagger.models.properties.StringProperty) Operation(io.swagger.models.Operation) Info(io.swagger.models.Info) PathParameter(io.swagger.models.parameters.PathParameter) Contact(io.swagger.models.Contact) RefProperty(io.swagger.models.properties.RefProperty) Response(io.swagger.models.Response) Swagger(io.swagger.models.Swagger) LongProperty(io.swagger.models.properties.LongProperty) Model(io.swagger.models.Model) Person(io.swagger.models.Person) SecurityRequirement(io.swagger.models.SecurityRequirement) Test(org.testng.annotations.Test)

Aggregations

OAuth2Definition (io.swagger.models.auth.OAuth2Definition)11 Test (org.testng.annotations.Test)9 Swagger (io.swagger.models.Swagger)3 JaxbAnnotationModule (com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule)2 Contact (io.swagger.models.Contact)1 Error (io.swagger.models.Error)1 Info (io.swagger.models.Info)1 Model (io.swagger.models.Model)1 Operation (io.swagger.models.Operation)1 Path (io.swagger.models.Path)1 Person (io.swagger.models.Person)1 Response (io.swagger.models.Response)1 SecurityRequirement (io.swagger.models.SecurityRequirement)1 PathParameter (io.swagger.models.parameters.PathParameter)1 QueryParameter (io.swagger.models.parameters.QueryParameter)1 LongProperty (io.swagger.models.properties.LongProperty)1 RefProperty (io.swagger.models.properties.RefProperty)1 StringProperty (io.swagger.models.properties.StringProperty)1