要求に応じて、ここに承認フィルタのシェルがあります。 シリアル化され、暗号化されたJSONオブジェクトを送信します。
パブリック・クラスXxxxxxFilter 継承AuthorizationFilterAttribute
Public Overrides Sub OnAuthorization(actionContext As System.Web.Http.Controllers.HttpActionContext)
Dim authHeader As System.Net.Http.Headers.AuthenticationHeaderValue = actionContext.Request.Headers.Authorization
If authHeader IsNot Nothing Then
'... then check that its set to basic auth with an actual parameter ....
If String.Compare("basic", authHeader.Scheme, True) = 0 AndAlso String.IsNullOrWhiteSpace(authHeader.Parameter) = False Then
Dim cred As String = Encoding.GetEncoding("iso-8859-1").GetString(Convert.FromBase64String(authHeader.Parameter))
' validate the cred value however needed
' you want to exit at this point if all is ok
End If
End If
' ... if we get this far then authentication has failed
actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized)
End Sub
エンドクラス
IPホワイトリストは、あなたの最も早い解決策になるが、これは、外部システムであれば、証拠を欺くされていません。私たちは、二次的なセキュリティ対策として、LAN上のいくつかのAPIサーバでIPホワイトリストを使用しています。 –
クライアント - 資格フローを使用します。または、パーソナライズされたアカウント(個人ごとに1つずつ)を持っている場合は、OpenIDフローの1つ(authCode)を使用します。範囲から外れて詳細に進む – Tseng
AuthorizationFilterAttributeを実装する基本HTTP認証を使用します。 – lcryder