# Authentication授權
VBA-Web帶有一些開箱即用的驗證器,您可以[創建自己的](https://github.com/VBA-tools/VBA-Web/wiki/Implementing-your-own-IAuthenticator)
## [](https://github.com/VBA-tools/VBA-Web/wiki/Authentication#set-up-an-existing-authenticator)設置現有身份驗證器
(確保項目中包含所需的身份驗證器類)
~~~vbnet
Dim Client As New WebClient
'// 創建一個新的IAuthenticator實現
Dim Auth As New ...Authenticator
' Setup authenticator...
'// 將身份驗證器附加到客戶端
Set Client.Authenticator = Auth
~~~
## [](https://github.com/VBA-tools/VBA-Web/wiki/Authentication#http-basic-authenticator)HTTP Basic Authenticator
這是標準的用戶名+密碼流。
*注意*: 用戶名和密碼已編碼,但未加密,因此在訪問服務時必須使用https才能確保傳輸安全
~~~vbnet
Dim Auth As New HttpBasicAuthenticator
Auth.Setup _
Username:="Your username", _
Password:="Your password"
~~~
## [](https://github.com/VBA-tools/VBA-Web/wiki/Authentication#oauth-10)OAuth 1.0
這是標準的[OAuth 1.0流程](http://oauth.net/core/1.0/),使用Consumer key和secret,以及Token key和secret來授權請求。
~~~vbnet
Dim Auth As new OAuth1Authenticator
Auth.Setup _
ConsumerKey:="Your consumer key", _
ConsumerSecret:="Your consumer secret", _
Token:="Your token", _
TokenSecret:="Your token secret", _
Realm:="Optional realm"
~~~
## [](https://github.com/VBA-tools/VBA-Web/wiki/Authentication#oauth-20---client-credentials-flow)OAuth 2.0 - Client-credentials flow
目前,VBA-Web僅支持OAuth 2.0的客戶端憑據流。
*注意:*
* 此身份驗證器是專為Salesforce實現而開發的,因此可能與實現OAuth 2.0的其他API不兼容。
* 用戶名和密碼已編碼,但未加密,因此在訪問服務時必須使用https才能確保傳輸安全
~~~vbnet
Dim Auth As new OAuth2Authenticator
Auth.Setup _
ClientId:="Your client id", _
ClientSecret:="Your client secret", _
Username:="Your username", _
Password:="Your password"
~~~
找不到符合您需求的驗證器? 創建你自己的!
有關詳細信息,請查看[實施您自己的IAuthenticator](https://github.com/VBA-tools/VBA-Web/wiki/Implementing-your-own-IAuthenticator)示例。
- README
- 指南
- 概述
- GET Request
- WebRequest
- 屬性
- Resource
- Method
- Body
- Format
- RequestFormat
- ResponseFormat
- CustomRequestFormat
- CustomResponseFormat
- ContentType
- Accept
- ContentLength
- FormattedResource
- Cookies
- Headers
- QuerystringParams
- UrlSegments
- 方法
- AddHeader
- SetHeader
- AddUrlSegment
- AddQuerystringParam
- AddCookie
- AddBodyParameter
- CreateFromOptions
- WebClient
- 屬性
- BaseUrl
- Authenticator
- TimeoutMs
- ProxyServer
- ProxyBypassList
- ProxyUsername
- ProxyPassword
- EnableAutoProxy
- Insecure
- FollowRedirects
- 方法
- Execute
- GetJson
- PostJson
- SetProxy
- GetFullUrl
- WebResponse
- 屬性
- StatusCode
- StatusDescription
- Content
- Data
- Body
- Headers
- Cookies
- 方法
- Update
- WebHelpers
- 屬性
- WebStatusCode
- WebMethod
- WebFormat
- UrlEncodingMode
- EnableLogging
- 方法
- LogDebug
- LogWarning
- LogError
- LogRequest
- LogResponse
- Obfuscate
- ParseJson
- ConvertToJson
- ParseUrlEncoded
- ConvertToUrlEncoded
- ParseXml
- ConvertToXml
- ParseByFormat
- ConvertToFormat
- UrlEncode
- UrlDecode
- Base64Encode
- Base64Decode
- RegisterConverter
- JoinUrl
- UrlParts
- CloneDictionary
- CloneCollection
- CreateKeyValue
- FindInKeyValues
- AddOrReplaceInKeyValues
- FormatToMediaType
- MethodToName
- HMACSHA1
- HMACSHA256
- MD5
- CreateNonce
- IWebAuthenticator
- 方法
- BeforeExecute
- AfterExecute
- PrepareHttp
- PrepareCurl
- WebAsyncWrapper
- 屬性
- Client
- 方法
- ExecuteAsync
- 范例
- Salesforce網站
- Google APIs
- Todoist API
- 其他主題
- 調試
- 授權
- 實現自己的IWebAuthenticator
- Url編碼