Authorization über access token eingebaut
This commit is contained in:
30
VERAG_REST_SERVER/App_Start/AddAuthTokenHeaderParamete.vb
Normal file
30
VERAG_REST_SERVER/App_Start/AddAuthTokenHeaderParamete.vb
Normal file
@@ -0,0 +1,30 @@
|
||||
'Imports System.Web.Http.Description
|
||||
'Imports System.Web.Http.Filters
|
||||
'Imports Microsoft.AspNetCore.Authorization
|
||||
'Imports Swashbuckle.Swagger
|
||||
|
||||
'Public Class AddAuthTokenHeaderParameter
|
||||
' Implements IOperationFilter
|
||||
|
||||
' Public Sub Apply(operation As Operation, schemaRegistry As SchemaRegistry, apiDescription As ApiDescription) Implements IOperationFilter.Apply
|
||||
|
||||
' Dim filterPipeline = apiDescription.ActionDescriptor.GetFilterPipeline()
|
||||
' Dim isAuthorized = filterPipeline.Select(Function(s) s.Instance).Any(Function(sc) sc.GetType().Equals(GetType(IAuthorizationFilter)))
|
||||
|
||||
' Dim allowAnonymous = apiDescription.ActionDescriptor.GetCustomAttributes(Of AllowAnonymousAttribute)().Any()
|
||||
|
||||
' If isAuthorized And (Not allowAnonymous) Then
|
||||
' If operation.parameters Is Nothing Then
|
||||
' operation.parameters = New List(Of Parameter)
|
||||
' End If
|
||||
' operation.parameters.Add(New Parameter With {
|
||||
' .name = "Authorization",
|
||||
' .in = "header",
|
||||
' .description = "access token",
|
||||
' .required = True,
|
||||
' .type = "string"
|
||||
' })
|
||||
' End If
|
||||
|
||||
' End Sub
|
||||
'End Class
|
||||
Reference in New Issue
Block a user