Authentication JHipster OAuth可以';无法获取令牌-405错误

Authentication JHipster OAuth可以';无法获取令牌-405错误,authentication,oauth,oauth-2.0,jhipster,Authentication,Oauth,Oauth 2.0,Jhipster,我正在尝试在本地JHipster服务器上获取OAuth2令牌以进行授权。 一切都是正确的设置和工作,我可以登录通过网络图形用户界面。 但当我试图通过cURL获取令牌时,我得到了不允许的POST方法 我的要求如下: curl-X POST-vu客户端:机密http://localhost:8080/oauth/token -H“Accept:application/json”-d“username=admin&password=admin&grant\u type=password&scope=r

我正在尝试在本地JHipster服务器上获取OAuth2令牌以进行授权。 一切都是正确的设置和工作,我可以登录通过网络图形用户界面。 但当我试图通过cURL获取令牌时,我得到了不允许的
POST方法

我的要求如下:


curl-X POST-vu客户端:机密http://localhost:8080/oauth/token -H“Accept:application/json”-d“username=admin&password=admin&grant\u type=password&scope=read&client\u id=CLIENTID&client\u secret=CLIENTSECRET”

使用默认生成的jhipster应用程序(3.5.0),这是为管理员用户创建令牌的方式:

> curl -X POST -u jhipsterapp:my-secret-token-to-change-in-production -i -H 'Accept:application/json' http://localhost:8080/oauth/token -d "username=admin&password=admin&grant_type=password&scope=read%20write"

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-Application-Context: jhipster:swagger,dev:8080
Cache-Control: no-store
Pragma: no-cache
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Frame-Options: DENY
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Fri, 22 Jul 2016 13:09:38 GMT

{
  "access_token" : "4a1ae413-5cd7-46e9-8a33-31698218d43e",
  "token_type" : "bearer",
  "refresh_token" : "537f231c-e6e0-4499-bbd8-9580eee02f79",
  "expires_in" : 1799,
  "scope" : "read write"
}
注意:这里是my.yo-rc.json:

{
  "generator-jhipster": {
    "jhipsterVersion": "3.5.0",
    "baseName": "jhipster",
    "packageName": "com.mycompany.myapp",
    "packageFolder": "com/mycompany/myapp",
    "serverPort": "8080",
    "authenticationType": "oauth2",
    "hibernateCache": "ehcache",
    "clusteredHttpSession": "no",
    "websocket": "no",
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "prodDatabaseType": "mysql",
    "searchEngine": "no",
    "buildTool": "maven",
    "useSass": false,
    "applicationType": "monolith",
    "testFrameworks": [
      "gatling"
    ],
    "jhiPrefix": "jhi",
    "enableTranslation": true,
    "nativeLanguage": "en",
    "languages": [
      "en"
    ]
  }
}
多亏了这篇文章,我已经测试了JHipster UAA以及JHipster版本5。
此命令可能是一个工作示例:

curl -X POST -v http://[server-ip]:9999/oauth/token -i 
-H "Accept: application/json" 
-H "Authorization: Basic aW50ZXJuYWw6aW50ZXJuYWw=" 
-d "username=admin&password=admin&grant_type=client_credentials&scope=web-app"
重要提示:

  • 用户名和密码必须替换为您的用户名和密码
  • 必须在标头中设置“clientId+”:“+clientSecret”的BASE64编码值。
    在我的例子中,BASE64('internal:internal')='aw50zxjuyw6aw50zxjuyww='1 可用于对文本进行编码
  • 因为您已经在消息头上放置了客户机Id和密码,所以不需要在消息体上提供它
  • 这可能是一个示例输出:

    {
    "access_token" : "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZSI6WyJ3ZWItYXBwIl0sImV4cCI6MTUzNTM2ODEyNiwiaWF0IjoxNTM1MzY2MzI2LCJqdGkiOiJiYjYwMWVkYS01NjUyLTQ5OTgtYWJkNS04YzYxZjA3Y2U1ODUiLCJjbGllbnRfaWQiOiJpbnRlcm5hbCJ9.lNqpfE7N6XJVFe9t7zPbwokU_zl4AFIAmQJZ_Hb2ok0vBpWrDMf3v6KgEEi5bN2iyRd0TQBelSIJothrsYHoTk0ZaeeK9BM97OJr4Uc8kLzn2Vp-xpBk8-n2PlwAKIRojoOxMnBp0nA2qjPieaPV2Fj1HETmK2gZ38lQcZ_KJLD-ug9AT9_N1E9SwRjt1yfZtd64IJZOQGqcZ05VCAj54jxH9lyvX-_1NY2Iq2aA5-cGbOftmv0sUjF15EiTGps6YtFUrJqKs8PmDofMImyqjAwB3yNObpg7c6PbeCXWYLAir5IOFdueTys3cLLyrhE78GJ3OiKSAA128nZSeUbiAg",
    "token_type" : "bearer",
    "expires_in" : 1799,
    "scope" : "web-app",
    "iat" : 1535366326,
    "jti" : "bb601eda-5652-4998-abd5-8c61f07ce585"
    * Connection #0 to host [server-ip] left intact
    }
    

    也许这就是你要找的?我认为您需要对“:”进行base64编码,您可能不需要在bodyNope中再次使用它,这不起作用。在jhipster上,使用github的OAuth示例,我通过该请求获得401,在我定制的jhipster上,使用更多选项生成,我获得405。这是因为示例使用了不同的客户端id:顺便问一下,您是否更改了自定义应用程序上的管理员密码?