0

使用 API 文档,我们尝试将其用于身份验证:使用公共应用程序进行主身份验证:</p>

http://developer.okta.com/docs/api/resources/authn.html#primary-authentication-with-public-application:通过公共应用程序使用用户名/密码凭据对用户进行身份验证

请求示例</p>

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"
      }
    }
  }
}

提前致谢!

4

1 回答 1

0

您正在为请求设置凭据,而不是发送 JSON 有效负载。

看看这个例子: http ://dotnetpad.com/7ri4979f

基于这个问题和答案

于 2016-04-15T15:10:50.980 回答