Commit Description
This commit is contained in:
@@ -25,7 +25,7 @@ Public Class BasicAuthenticationAttribute
|
||||
If isValid Then
|
||||
Dim principal = New GenericPrincipal(New GenericIdentity(userName), Nothing)
|
||||
Thread.CurrentPrincipal = principal
|
||||
actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.OK, "User " & userName & " successfully authenticated")
|
||||
'actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.OK, "User " & userName & " successfully authenticated")
|
||||
Return
|
||||
End If
|
||||
End If
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
Imports System.Net.Http
|
||||
Imports System.IO
|
||||
Imports System.Net.Http
|
||||
Imports System.Reflection
|
||||
Imports System.Web.Http
|
||||
Imports System.Web.Http.Description
|
||||
Imports Microsoft.Extensions.Options
|
||||
@@ -19,9 +21,13 @@ Public Class SwaggerConfig
|
||||
Public Shared Sub Register(ByVal config As HttpConfiguration)
|
||||
Dim thisAssembly = GetType(SwaggerConfig).Assembly
|
||||
|
||||
Dim baseDirectory = AppDomain.CurrentDomain.BaseDirectory
|
||||
baseDirectory &= "\bin\"
|
||||
Dim commentsFileName = Assembly.GetExecutingAssembly().GetName().Name + ".XML"
|
||||
Dim commentsFile = Path.Combine(baseDirectory, commentsFileName)
|
||||
|
||||
GlobalConfiguration.Configuration.EnableSwagger(Function(c)
|
||||
'c.SingleApiVersion("v1", descr)
|
||||
|
||||
|
||||
c.PrettyPrint()
|
||||
c.MultipleApiVersions(Function(apiDesc, targetApiVersion) ResolveVersionSupportByRouteConstraint(apiDesc, targetApiVersion), Function(vc)
|
||||
@@ -41,33 +47,29 @@ Public Class SwaggerConfig
|
||||
End Function)
|
||||
|
||||
|
||||
' c.OAuth2("oauth2").Description("OAuth2 Implicit Grant").Flow("implicit").AuthorizationUrl("http://petstore.swagger.wordnik.com/api/oauth/dialog").Scopes(Function(scopes)
|
||||
'End Function)
|
||||
c.BasicAuth("basic").Description("Basic HTTP Authentication")
|
||||
|
||||
c.IncludeXmlComments(commentsFile)
|
||||
|
||||
'c.ApiKey("apiKey").Description("API Key Authentication").Name("apiKey").In("header")
|
||||
|
||||
'c.RootUrl(Function(req) req.GetRouteData)
|
||||
|
||||
'c.OperationFilter(Of AddAuthorizationHeaderParameterOperationFilter)()
|
||||
|
||||
'c.OperationFilter(Of BasicAuthenticationAttribute)()
|
||||
|
||||
|
||||
'c.IncludeXmlComments($"{AppDomain.CurrentDomain.BaseDirectory}\bin\MyApi.XML")
|
||||
'c.RootUrl(Function(req) req.GetRouteData)
|
||||
|
||||
End Function).EnableSwaggerUi(Function(c)
|
||||
c.DocumentTitle(descr)
|
||||
|
||||
c.EnableDiscoveryUrlSelector()
|
||||
c.DocExpansion(DocExpansion.Full)
|
||||
'c.EnableApiKeySupport("apiKey", "header")
|
||||
'c.CustomAsset("index", yourAssembly, "YourWebApiProject.SwaggerExtensions.index.html")
|
||||
'c.EnableOAuth2Support(clientId:="test-client-id", clientSecret:=Nothing, realm:="test-realm", appName:="Swagger UI")
|
||||
'additionalQueryStringParams:=New Dictionary(Of String, String)() From {
|
||||
' {"foo", "bar"}
|
||||
'})
|
||||
c.DocExpansion(DocExpansion.List)
|
||||
|
||||
c.CustomAsset("index", thisAssembly, "VERAG_REST_SERVER.my_index.html")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
End Function)
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
Imports System.Net.Http.Headers
|
||||
Imports System.Security.Claims
|
||||
Imports System.Text.Encodings.Web
|
||||
Imports System.Threading.Tasks
|
||||
Imports Microsoft.AspNetCore.Authentication
|
||||
Imports Microsoft.Extensions.Logging
|
||||
Imports Microsoft.Extensions.Options
|
||||
Imports Microsoft.AspNetCore.Http.Abstractions
|
||||
|
||||
|
||||
Public Class BasicAuthentificationHandler
|
||||
Inherits AuthenticationHandler(Of AuthenticationSchemeOptions)
|
||||
|
||||
ReadOnly _userService As IUserService
|
||||
|
||||
|
||||
Public Sub New(userService As IUserService, options As Microsoft.Extensions.Options.IOptionsMonitor(Of AuthenticationSchemeOptions), logger As ILoggerFactory, encoder As UrlEncoder, clock As ISystemClock)
|
||||
|
||||
MyBase.New(options, logger, encoder, clock)
|
||||
_userService = userService
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
Protected Overrides Function HandleChallengeAsync(properties As AuthenticationProperties) As Task
|
||||
GetResponse().Headers("WWW-Authenticate") = "Basic"
|
||||
Return MyBase.HandleChallengeAsync(properties)
|
||||
End Function
|
||||
|
||||
Private Function GetResponse() As Object
|
||||
Return Response
|
||||
End Function
|
||||
|
||||
Protected Overrides Function HandleAuthenticateAsync() As Task(Of AuthenticateResult)
|
||||
|
||||
Dim username As String = ""
|
||||
|
||||
Try
|
||||
|
||||
Dim authHeader = AuthenticationHeaderValue.Parse(GetResponse().Headers("Authorization"))
|
||||
Dim credentials = Encoding.UTF8.GetString(Convert.FromBase64String(authHeader.Parameter)).Split(":")
|
||||
username = credentials.FirstOrDefault
|
||||
Dim password = credentials.LastOrDefault
|
||||
|
||||
If Not _userService.CheckUser(username, password) Then
|
||||
Throw New NotImplementedException("Invalid Username or password")
|
||||
End If
|
||||
|
||||
|
||||
|
||||
Catch ex As Exception
|
||||
|
||||
Return Task.FromResult(AuthenticateResult.Fail(ex.Message))
|
||||
|
||||
End Try
|
||||
|
||||
Dim claims = {New Claim(ClaimTypes.Name, username)}
|
||||
Dim idendity = New ClaimsIdentity(claims, Scheme.Name)
|
||||
Dim principal = New ClaimsPrincipal(idendity)
|
||||
Dim ticket = New AuthenticationTicket(principal, Scheme.Name)
|
||||
|
||||
Return Task.FromResult(AuthenticateResult.Success(ticket))
|
||||
|
||||
|
||||
|
||||
|
||||
End Function
|
||||
End Class
|
||||
@@ -12,26 +12,24 @@ Namespace ApiController.Controllers
|
||||
|
||||
|
||||
|
||||
'If myTokenAttribute Then
|
||||
|
||||
'If operation.parameters Is Nothing Then
|
||||
' operation.parameters = New List(Of Parameter)()
|
||||
' End If
|
||||
|
||||
' operation.parameters.Add(New Parameter() With {
|
||||
' .name = "Authorization Token",
|
||||
' .[in] = "header",
|
||||
' .description = "my token description",
|
||||
' .required = True,
|
||||
' .type = "string"
|
||||
' })
|
||||
'End If
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Gets the Hello World Response
|
||||
''' </summary>
|
||||
''' <returns>A SharePriceResponse which contains the price of the share</returns>
|
||||
''' <response code="200">Returns 200 And Hallo World</response>
|
||||
''' <response code="400">Returns 400 if the query Is invalid</response>
|
||||
Public Function GetValue() As String
|
||||
Return "Hello world!"
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Set the Test
|
||||
''' </summary>
|
||||
''' <param name="Traviso">TRAviso</param>
|
||||
''' <returns>A SharePriceResponse which contains the price of the share</returns>
|
||||
''' <response code="200">Returns 200 and the TRAviso-JSON-Object</response>
|
||||
''' <response code="400">Returns 400 if the query Is invalid</response>
|
||||
''' <response code="401">Returns 401 if your are not authorized</response>
|
||||
Public Function PostValue(ByVal API_AVISO As VERAG_PROG_ALLGEMEIN.cVERAG_in_TRAviso) As String
|
||||
VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM = False
|
||||
VERAG_PROG_ALLGEMEIN.cAllgemein.ERR_OP_GLOBAL = VERAG_PROG_ALLGEMEIN.ERROR_OP.MAIL
|
||||
@@ -216,6 +214,9 @@ Namespace ApiController.Controllers
|
||||
Public Class AVISO1TESTController
|
||||
Inherits System.Web.Http.ApiController
|
||||
|
||||
''' <summary>
|
||||
''' Gets the Hello World Response
|
||||
''' </summary>
|
||||
Public Function GetValue() As String
|
||||
Return "Hello world!"
|
||||
End Function
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
Public Interface IUserService
|
||||
|
||||
Function CheckUser(ByVal username As String, ByVal passowrd As String)
|
||||
|
||||
End Interface
|
||||
@@ -1,7 +0,0 @@
|
||||
Public Class Service
|
||||
Implements IUserService
|
||||
|
||||
Public Function CheckUser(username As String, passowrd As String) As Object Implements IUserService.CheckUser
|
||||
Return username.Equals("testuser") & passowrd.Equals("pwd")
|
||||
End Function
|
||||
End Class
|
||||
167
VERAG_REST_SERVER/SwaggerExtensions/my_index.html
Normal file
167
VERAG_REST_SERVER/SwaggerExtensions/my_index.html
Normal file
@@ -0,0 +1,167 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Swagger UI</title>
|
||||
<link rel="icon" type="image/png" href="images/favicon-32x32-png" sizes="32x32" />
|
||||
<link rel="icon" type="image/png" href="images/favicon-16x16-png" sizes="16x16" />
|
||||
<link href='css/typography-css' media='screen' rel='stylesheet' type='text/css' />
|
||||
<link href='css/reset-css' media='screen' rel='stylesheet' type='text/css' />
|
||||
<link href='css/screen-css' media='screen' rel='stylesheet' type='text/css' />
|
||||
<link href='css/reset-css' media='print' rel='stylesheet' type='text/css' />
|
||||
<link href='css/print-css' media='print' rel='stylesheet' type='text/css' />
|
||||
%(StylesheetIncludes)
|
||||
|
||||
<script src='lib/object-assign-pollyfill-js' type='text/javascript'></script>
|
||||
<script src='lib/jquery-1-8-0-min-js' type='text/javascript'></script>
|
||||
<script src='lib/jquery-slideto-min-js' type='text/javascript'></script>
|
||||
<script src='lib/jquery-wiggle-min-js' type='text/javascript'></script>
|
||||
<script src='lib/jquery-ba-bbq-min-js' type='text/javascript'></script>
|
||||
<script src='lib/handlebars-4-0-5-js' type='text/javascript'></script>
|
||||
<script src='lib/lodash-min-js' type='text/javascript'></script>
|
||||
<script src='lib/backbone-min-js' type='text/javascript'></script>
|
||||
<script src='swagger-ui-min-js' type='text/javascript'></script>
|
||||
<script src='lib/highlight-9-1-0-pack-js' type='text/javascript'></script>
|
||||
<script src='lib/highlight-9-1-0-pack_extended-js' type='text/javascript'></script>
|
||||
<script src='lib/jsoneditor-min-js' type='text/javascript'></script>
|
||||
<script src='lib/marked-js' type='text/javascript'></script>
|
||||
<script src='lib/swagger-oauth-js' type='text/javascript'></script>
|
||||
|
||||
<!-- Some basic translations -->
|
||||
<!-- <script src='lang/translator.js' type='text/javascript'></script> -->
|
||||
<!-- <script src='lang/ru.js' type='text/javascript'></script> -->
|
||||
<!-- <script src='lang/en.js' type='text/javascript'></script> -->
|
||||
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
|
||||
// Get Swashbuckle config into JavaScript
|
||||
function arrayFrom(configString) {
|
||||
return (configString !== "") ? configString.split('|') : [];
|
||||
}
|
||||
|
||||
function stringOrNullFrom(configString) {
|
||||
return (configString !== "null") ? configString : null;
|
||||
}
|
||||
|
||||
window.swashbuckleConfig = {
|
||||
rootUrl: '%(RootUrl)',
|
||||
discoveryPaths: arrayFrom('%(DiscoveryPaths)'),
|
||||
booleanValues: arrayFrom('%(BooleanValues)'),
|
||||
validatorUrl: stringOrNullFrom('%(ValidatorUrl)'),
|
||||
customScripts: arrayFrom('%(CustomScripts)'),
|
||||
docExpansion: '%(DocExpansion)',
|
||||
supportedSubmitMethods: arrayFrom('%(SupportedSubmitMethods)'),
|
||||
oAuth2Enabled: ('%(OAuth2Enabled)' == 'true'),
|
||||
oAuth2ClientId: '%(OAuth2ClientId)',
|
||||
oAuth2ClientSecret: '%(OAuth2ClientSecret)',
|
||||
oAuth2Realm: '%(OAuth2Realm)',
|
||||
oAuth2AppName: '%(OAuth2AppName)',
|
||||
oAuth2ScopeSeperator: '%(OAuth2ScopeSeperator)',
|
||||
oAuth2AdditionalQueryStringParams: JSON.parse('%(OAuth2AdditionalQueryStringParams)'),
|
||||
apiKeyName: '%(ApiKeyName)',
|
||||
apiKeyIn: '%(ApiKeyIn)'
|
||||
};
|
||||
|
||||
hljs.configure({
|
||||
highlightSizeThreshold: 5000
|
||||
});
|
||||
|
||||
// Pre load translate...
|
||||
if(window.SwaggerTranslator) {
|
||||
window.SwaggerTranslator.translate();
|
||||
}
|
||||
window.swaggerUi = new SwaggerUi({
|
||||
url: swashbuckleConfig.rootUrl + "/" + swashbuckleConfig.discoveryPaths[0],
|
||||
dom_id: "swagger-ui-container",
|
||||
booleanValues: swashbuckleConfig.booleanValues,
|
||||
supportedSubmitMethods: swashbuckleConfig.supportedSubmitMethods,
|
||||
onComplete: function(swaggerApi, swaggerUi){
|
||||
if (typeof initOAuth == "function" && swashbuckleConfig.oAuth2Enabled) {
|
||||
initOAuth({
|
||||
clientId: swashbuckleConfig.oAuth2ClientId,
|
||||
clientSecret: swashbuckleConfig.oAuth2ClientSecret,
|
||||
realm: swashbuckleConfig.oAuth2Realm,
|
||||
appName: swashbuckleConfig.oAuth2AppName,
|
||||
scopeSeparator: swashbuckleConfig.oAuth2ScopeSeperator,
|
||||
additionalQueryStringParams: swashbuckleConfig.oAuth2AdditionalQueryStringParams
|
||||
});
|
||||
|
||||
|
||||
requestInterceptor: (req) => {
|
||||
if (!req.loadSpec) {
|
||||
// Add the header to "try it out" calls but not spec fetches
|
||||
var token = btoa("username" + ":" + "password");
|
||||
req.headers.Authorization = "Basic " + token;
|
||||
}
|
||||
return req;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(window.SwaggerTranslator) {
|
||||
window.SwaggerTranslator.translate();
|
||||
}
|
||||
|
||||
addApiKeyAuthorization();
|
||||
|
||||
window.swaggerApi = swaggerApi;
|
||||
_.each(swashbuckleConfig.customScripts, function (script) {
|
||||
$.getScript(script);
|
||||
});
|
||||
},
|
||||
onFailure: function(data) {
|
||||
log("Unable to Load SwaggerUI");
|
||||
},
|
||||
docExpansion: swashbuckleConfig.docExpansion,
|
||||
jsonEditor: false,
|
||||
apisSorter: null, // default to server
|
||||
defaultModelRendering: 'schema',
|
||||
showRequestHeaders: false,
|
||||
oauth2RedirectUrl: window.location.href.replace('index', 'o2c-html').split('#')[0]
|
||||
});
|
||||
|
||||
if (window.swashbuckleConfig.validatorUrl !== '')
|
||||
window.swaggerUi.options.validatorUrl = window.swashbuckleConfig.validatorUrl;
|
||||
|
||||
function addApiKeyAuthorization() {
|
||||
var key = $('#input_apiKey')[0].value;
|
||||
if (key && key.trim() != "") {
|
||||
if (swashbuckleConfig.apiKeyIn === "query") {
|
||||
key = encodeURIComponent(key);
|
||||
}
|
||||
var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization(swashbuckleConfig.apiKeyName, key, swashbuckleConfig.apiKeyIn);
|
||||
window.swaggerUi.api.clientAuthorizations.add("api_key", apiKeyAuth);
|
||||
log("added key " + key);
|
||||
}
|
||||
}
|
||||
$('#input_apiKey').change(addApiKeyAuthorization);
|
||||
|
||||
window.swaggerUi.load();
|
||||
|
||||
function log() {
|
||||
if ('console' in window) {
|
||||
console.log.apply(console, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body class="swagger-section">
|
||||
<div id='header'>
|
||||
<div class="swagger-ui-wrap">
|
||||
<a id="logo" href="http://swagger.io"><img class="logo__img" alt="swagger" height="30" width="30" src="images/logo_small-png" /><span class="logo__title">swagger</span></a>
|
||||
<form id='api_selector'>
|
||||
<div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text" /></div>
|
||||
<!--<div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text" /></div>-->
|
||||
<div class='input'><a id="explore" class="header__btn" href="#" data-sw-translate>Explore</a></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="message-bar" class="swagger-ui-wrap" data-sw-translate> </div>
|
||||
<div id="swagger-ui-container" class="swagger-ui-wrap"></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -298,6 +298,7 @@
|
||||
<Import Include="System.Web.UI.HtmlControls" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="SwaggerExtensions\my_index.html" />
|
||||
<Content Include="App_Start\SwaggerConfig.cs" />
|
||||
<Content Include="Global.asax" />
|
||||
<Content Include="Web.config" />
|
||||
@@ -308,7 +309,6 @@
|
||||
<Compile Include="App_Start\RouteConfig.vb" />
|
||||
<Compile Include="App_Start\SwaggerConfig.vb" />
|
||||
<Compile Include="App_Start\WebApiConfig.vb" />
|
||||
<Compile Include="BasicAuthentificationHandler.vb" />
|
||||
<Compile Include="Controllers\V1\AvisoController\AVISOController.vb" />
|
||||
<Compile Include="Controllers\V1\CustomsDeclaration\CustomsDeclarationController.vb" />
|
||||
<Compile Include="Controllers\V2\CustomsDeclarationController\CustomDeclarationController.vb" />
|
||||
@@ -321,7 +321,6 @@
|
||||
<Compile Include="Global.asax.vb">
|
||||
<DependentUpon>Global.asax</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="IService\IUserService.vb" />
|
||||
<Compile Include="Models\cTEST.vb" />
|
||||
<Compile Include="Models\cVERAG_in_shippmentOLD.vb" />
|
||||
<Compile Include="My Project\AssemblyInfo.vb" />
|
||||
@@ -343,7 +342,6 @@
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<Compile Include="Service\Service.vb" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="My Project\Resources.resx">
|
||||
|
||||
Reference in New Issue
Block a user