2016-07-21 70 views
1

我正尝试在本地JHipster服务器上获取授权OAuth2令牌。 所有设置都正确并正常工作,我可以通过Web GUI登录。 但是,当我试图让通过卷曲令牌,我得到POST method not allowedJHipster OAuth无法获取令牌 - 405错误

我卷曲reques是如下:

curl -X POST -vu client:secret http://localhost:8080/oauth/token -H "Accept: application/json" -d "username=admin&password=admin&grant_type=password&scope=read&client_id=CLIENTID&client_secret=CLIENTSECRET"

+1

也许http://stackoverflow.com/a/34834735/1098564是你在找什么?我认为你需要base64编码你的“”,你可能不需要它在身体 – sdoxsee

+0

不,没有工作。 –

回答

0

使用默认生成jhipster应用(3.5.0),这是你会怎样卷曲令牌admin用户:

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

注:这里是我的.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" 
    ] 
    } 
} 
+0

jioster与从github的OAuth示例我得到401与该请求和我的自定义jhipster与一些更多的选项,我得到405 405。与您的卷曲请求。 –

+0

这是因为该示例使用不同的客户端ID:https://github.com/jhipster/jhipster-sample-app-oauth2/blob/master/src/main/resources/config/application-dev.yml#L69 Btw确实你改变你的自定义应用程序的管理员密码? – sdoxsee