如何使用消费者密钥/密钥从WSO2获取OAuth令牌?

时间:2012-12-18 20:27:45

标签: oauth wso2

我是WSO2的新手,我还在评估它 - 主要是通过Fiddler。我的理解是,我应该能够通过调用WSO2的Login API来获取OAuth令牌。我尝试了各种URL(在Fiddler中):

//基于博文:http://lalajisureshika.blogspot.com/2012/11/generate-application-tokens-user-tokens.html

http://localhost:8280/login?grant_type=password&username=admin&password=admin&scope=PRODUCTION
Authorization: Basic cFNET0lab1RnMHRBODRCWmQ4bTRBbnp1c0RZYTpZREIzZzh3RXhQOV92ZTdZX1drYVhieWx5ZlVh

当我执行上述网址时,我收到(403)在给定请求的API中找不到匹配资源

我可以使用“访问令牌”(通过Bearer标签)和API工作。我无法弄清楚如何获取OAuth令牌以供实际运行时使用。

任何指针/想法?

---谢谢,杰夫

4 个答案:

答案 0 :(得分:2)

  1. 设置Identity Server [domain:9443]
  2. 创建OAuth2应用程序,并获取客户端ID +使用者密钥
  3. 获取clientId的Base64编码:consumerKey - 将其替换为Authorization Basic xxxxx
  4. 替换REST端点以生成令牌 - 您应该在管理控制台上获取oauth应用程序[在我们的案例中为https://domain:9443/oauth2/token]
  5. 以下curl命令应该给你回复

    curl -k -d "grant_type=password&username=sasikumar@domain.com&password=xxxx1234" -H "Authorization" -H "Authorization: Basic X2dhWllidkN6TDNQY2ZqSmVBQ1lsNlg2SFdRYTpSQVlSMmxOZzQ0enU5ZXVGSDRDVXdOUWRudlVh, Content-type=application/x-www-form-urlencoded"  https://domain:9443/oauth2/token
    

答案 1 :(得分:0)

您可以直接访问OAuth2 REST Web服务以访问令牌。以下是使用curl访问令牌的方法

curl --user ConsumerKey:ConsumerSecret  -k -d "grant_type=password&username=admin&password=admin" -H "Content-Type:application/x-www-form-urlencoded" https://localhost:9443/oauth2endpoints/token

答案 2 :(得分:0)

以下是默认情况下使用linux中提供的cURL工具的示例(可以明确地为windows安装cURL)

curl -v 4 -X POST -H“Content-Type:application / x-www-form-urlencoded; charset = UTF-8”-k -d“grant_type = password& username = & password = & client_id = & client_secret = “https:// :9443 / oauth2 /令牌

获取client_secret& client_id你必须在wso2is中注册一个应用程序。

有免费工具可用于构建上述请求或直接使用上述参数并获取令牌。

答案 3 :(得分:0)

设置Identity Server [domain:9443] 创建OAuth2应用程序,并获取客户端ID,使用者密钥和URL。

使用带有详细信息的“海报”处理发布请求,

网址: - 从oauth应用程序获取

内容类型: - application / x-www-form-urlencoded

正文: - grant_type =密码&用户名=您的用户名&密码=您的密码& client_id =您的客户ID&client_secret =您的客户密码

相关问题