OAuth2部分安装和运行说明 - VegetaPn/soahomework_commerce GitHub Wiki
OAuth2部分运行和使用说明
本次作业的OAuth2部分参考:http://wso2.com/library/tutorials/2015/05/tutorial-hosting-restful-web-services-using-oauth-with-the-wso2-platform-0/
安装&启动
我已经把WSO2 Identity Server(IS)中的关键文件放到了项目中的‘OAuth2相关部分’文件夹中。替换本机的IS文件操作如下
- 下载WSO2 Identity Server5.1
- 将本项目的OAuth2相关部分/wso2is-5.1.0/repository/components/default文件夹替换掉下载好的IS中的对应文件夹
- 将本项目的OAuth2相关部分/wso2is-5.1.0/repository 下的除了default的其他文件夹替换掉下载好的IS中的对应文件夹
- 将本项目的OAuth2相关部分/wso2is-5.1.0 下的除了repository的其他文件夹替换掉下载好的IS中的对应文件夹
进入wso2is-5.1.0/bin目录后可直接运行脚本启动IS。
由于在esb的InSequence中Oauth配置项的端口是写死的,为9444,所以要保证IS运行所用的端口也为9444,否则要改EcommerceAPI.xml文件,将oauthService中remoteServiceUrl里的端口号改成自己的。
使用
系统中已加入Oauth认证,所以在访问api的时候必须在header中带上Authorization=Bearer 92eec608d553120455be6139c97bfe64的形式。key为Authorization,value为bearer+空格+access_token
如果没用携带access_token或者携带了错误的access_token则不会返回正确信息
如何获取access_token
- 启动IS
- 向IS发起请求以获取access_token(可以用Curl命令,也可以用Postman等工具): curl -v -k -X POST --user CL7hb_C7hAmNryv7dzVm9VDT6xMa:Ikb8fAFPKPSaapdznNhBGTExJnMa -H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" -d 'grant_type=password&username=admin&password=admin' https://localhost:9444/oauth2/token
- 记录返回的access_token值