Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bearer Authentication #26

Open
javierggi opened this issue Jun 22, 2018 · 1 comment
Open

Bearer Authentication #26

javierggi opened this issue Jun 22, 2018 · 1 comment

Comments

@javierggi
Copy link

Hi, I am trying to implement a Bearer token authentication. I am experiencing the exact same problems as explained in this issue: https://github.com/springfox/springfox/issues/2194.

I followed all recommendations but I am still unable to see the "lock" at the methods I am trying to secure.

My Docket method is as follows:

@Bean
    Docket api() {
        new Docket(DocumentationType.SWAGGER_2)
            .ignoredParameterTypes(MetaClass)
            .select()
                .apis(RequestHandlerSelectors.basePackage(myPackage))
                .paths(not(ant("/error")))
                .build()
            .host(myHost)
            .pathMapping(myPath)
            .securitySchemes(Arrays.asList(apiKey()))
            .securityContexts(Arrays.asList(securityContext()))
            .useDefaultResponseMessages(false)
    }

The other security related methods are:

@Bean
SecurityConfiguration security() {
    return SecurityConfigurationBuilder.builder()
            .clientId("test")
            .clientSecret("test-secret")
            .scopeSeparator("")
            .useBasicAuthenticationWithAccessCodeGrant(false)
            .build()
}

private ApiKey apiKey() {
    return new ApiKey("apiKey", "Authorization", "header")
}

private SecurityContext securityContext() {
    return SecurityContext.builder()
            .securityReferences(defaultAuth())
            .forPaths(PathSelectors.regex("/accounts/api/v2.*"))
            .build()
}

private List<SecurityReference> defaultAuth() {
    AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything")
    AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]
    authorizationScopes[0] = authorizationScope
    return Arrays.asList(new SecurityReference("apiKey", authorizationScopes))
}

I even added the code at my API methods as follows:

@ApiOperation(value="Create new.", authorizations = @Authorization("apiKey"))

My end result is having a popup where I can successfully input a token but it is not being passed on to the requests. I am using the following:

compile "io.springfox:springfox-swagger2:2.8.0"
compile "io.springfox:springfox-swagger-ui:2.8.0"
compile "io.springfox.grails:springfox-grails:1.0.0"

Any help would be greatly appreciated. Cheers.

@dilipkrish
Copy link
Member

I'll take a look and let u know.

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

No branches or pull requests

2 participants