使用API文档,我们尝试使用它来进行身份验证: 公共应用程序的主要身份验证:
http://developer.okta.com/docs/api/resources/authn.html#primary-authentication-with-public-application: 通过公共应用程序使用用户名/密码凭证对用户进行身份验证
请求示例
curl -v -X POST \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{
"username": "dade.murphy@example.com",
"password": "correcthorsebatterystaple",
"relayState": "/myapp/some/deep/link/i/want/to/return/to",
"options": {
"multiOptionalFactorEnroll": false,
"warnBeforePasswordExpired": false
}
}'

在VB.Net中尝试这个,我们得到:
Dim request As WebRequest = WebRequest.Create("https://dev-XXX.oktapreview.com/api/v1/authn")
request.Credentials = New NetworkCredential(.UserName, .Password)
request.ContentType = "application/json"
request.Method = "POST"
Dim response As WebResponse = request.GetResponse()

当我们得到响应时,它会给出错误"远程服务器返回错误:(400)错误请求。"并没有更多有用的信息。
显然我们要做的是使用格式正确的参数进行WebRequest并返回我们可以查询成功响应的WebResponse:
{
"expiresAt": "2015-11-03T10:15:57.000Z",
"status": "SUCCESS",
"relayState": "/myapp/some/deep/link/i/want/to/return/to",
"sessionToken": "00Fpzf4en68pCXTsMjcX8JPMctzN2Wiw4LDOBL_9pe",
"_embedded": {
"user": {
"id": "00ub0oNGTSWTBKOLGLNR",
"passwordChanged": "2015-09-08T20:14:45.000Z",
"profile": {
"login": "dade.murphy@example.com",
"firstName": "Dade",
"lastName": "Murphy",
"locale": "en_US",
"timeZone": "America/Los_Angeles"
}
}
}
}

提前致谢!
答案 0 :(得分:0)
You are setting credentials on the request instead of sending the JSON payload.
Check out this example: http://dotnetpad.com/7ri4979f
Based off this question and answer.