1
1
package no.nav.sifinnsynapi.config
2
2
3
+ import io.swagger.v3.oas.models.Components
3
4
import io.swagger.v3.oas.models.ExternalDocumentation
4
5
import io.swagger.v3.oas.models.OpenAPI
5
6
import io.swagger.v3.oas.models.info.Info
7
+ import io.swagger.v3.oas.models.security.*
6
8
import io.swagger.v3.oas.models.servers.Server
9
+ import org.springframework.beans.factory.annotation.Value
10
+ import org.springframework.context.EnvironmentAware
7
11
import org.springframework.context.annotation.Bean
8
12
import org.springframework.context.annotation.Configuration
9
- import org.springframework.context.annotation.Profile
13
+ import org.springframework.core.env.Environment
10
14
11
15
@Configuration
12
- @Profile(" local" , " dev-gcp" )
13
- class SwaggerConfiguration {
16
+ class SwaggerConfiguration (
17
+ @Value(" \$ {springdoc.oAuthFlow.authorizationUrl}" ) val authorizationUrl : String ,
18
+ @Value(" \$ {springdoc.oAuthFlow.tokenUrl}" ) val tokenUrl : String ,
19
+ @Value(" \$ {springdoc.oAuthFlow.apiScope}" ) val apiScope : String
20
+ ) : EnvironmentAware {
21
+
22
+ private var env: Environment ? = null
23
+
14
24
15
25
@Bean
16
26
fun openAPI (): OpenAPI {
@@ -28,6 +38,37 @@ class SwaggerConfiguration {
28
38
ExternalDocumentation ()
29
39
.description(" Sif Innsyn Api GitHub repository" )
30
40
.url(" https://github.com/navikt/sif-innsyn-api" )
41
+ ).components(
42
+ Components ()
43
+ .addSecuritySchemes(" oauth2" , azureLogin())
44
+ )
45
+ .addSecurityItem(
46
+ SecurityRequirement ()
47
+ .addList(" oauth2" , listOf (" read" , " write" ))
48
+ .addList(" Authorization" )
31
49
)
32
50
}
51
+
52
+
53
+ private fun azureLogin (): SecurityScheme {
54
+ return SecurityScheme ()
55
+ .name(" oauth2" )
56
+ .type(SecurityScheme .Type .OAUTH2 )
57
+ .scheme(" oauth2" )
58
+ .`in `(SecurityScheme .In .HEADER )
59
+ .flows(
60
+ OAuthFlows ()
61
+ .authorizationCode(
62
+ OAuthFlow ().authorizationUrl(authorizationUrl)
63
+ .tokenUrl(tokenUrl)
64
+ .scopes(Scopes ().addString(apiScope, " read,write" ))
65
+ )
66
+ )
67
+ }
68
+
69
+ override fun setEnvironment (environment : Environment ) {
70
+ this .env = environment;
71
+ }
72
+
73
+
33
74
}
0 commit comments