【问题标题】:How to implement oAuth 2.0 in Tizen如何在 Tizen 中实现 oAuth 2.0
【发布时间】:2013-03-08 01:58:41
【问题描述】:

我正在尝试在 Tizen 中使用 oAuth 2.0 实现 google 身份验证。我正在遵循here 的步骤。根据链接中的说明,我可以获得用户代码。但我总是收到获取访问和刷新令牌的无效请求。我的要求如下。

var urlToken ="https://accounts.google.com/o/oauth2/token?"+ 
        encodeURI("client_id=<<my client id>>&" +
        "client_secret=<<my client secret>>&" + 
        "code=<<Device code received in first step>>&" +
        "grant_type=authorization_code");
$.ajax({
    url:urlToken,
    type:"POST",        
    headers:{
        "Content-Type": "application/x-www-form-urlencoded",
        "Content-length" : "250"
    },
    accepts: "applicatin/json",
    success:function(response){
        console.log("access token response success");
        console.log(response.access_token)
    },
    error:failure
});

我无法弄清楚出了什么问题。请更新它,还有其他方法可以实现。

注意:我正在尝试从 Tizen Web 应用程序实现这一点。

【问题讨论】:

  • 为什么要手动设置"Content-length" : "250" 标头? “我总是收到无效请求”是什么意思 - 谷歌是否返回此信息?或者请求在发送之前是否在某些传输层上失败?
  • 内容长度是我在其他问卷中得到的选项之一。删除它也会给我同样的结果。无效请求是我可以使用 Firefox 的 rest 客户端看到的返回响应。它给出了 400 Bad request。是的,我收到了谷歌的回复。一个
  • 您是否尝试过让它在 Tizen 之外工作?我不熟悉那个库,所以我不确定我是否以及如何影响您的请求。
  • 是的。我尝试使用restclient(Firefox插件)通过简单的ajax请求来做到这一点。
  • 还有...?结果是相同的“无效请求”?

标签: javascript jquery oauth-2.0 tizen tizen-web-app


【解决方案1】:

我得到了使用以下代码的东西。我在查询字符串中标记数据以及显式设置内容类型和内容长度时犯了一个错误。内容类型默认为“application/x-www-form-urlencode”。通过随机点击得到解决方案。

var urlToken ="https://accounts.google.com/o/oauth2/token"+ 
var dataValue = "client_id=<<my client id>>&" +
        "client_secret=<<my client secret>>&" + 
        "code=<<Device code received in first step>>&" +
        "grant_type=http://oauth.net/grant_type/device/1.0";
$.ajax({
    url:urlToken,
    data:dataValue,
    crossDomain:true,
    type:"POST",
    success:function(response){
      if(response.error != null){
            <<Call the same function again>>;
        }
        else{
            console.log("Access Token :" + response.access_token);
            console.log("Token Type : " + response.token_type);
            console.log("Expires : " + response.expires_in);
            console.log("Refresh Token : " + response.refresh_token);
        }
    },
    error:failure
});

谢谢WTK

我相信thisthis 会有所帮助

【讨论】:

  • 嗨@Brune,我正在尝试使用谷歌登录开发tizen网络应用程序,你能帮我解决这个问题吗?
  • @venky 当然.. 但我已经接触过 google auth 和 tizen 一段时间了。我不确定我提供的信息是否会对您有所帮助.. 如果我是正确的,我在 tizen 中使用的版本现在已经过时了.. 但是,请提出您的查询.. 我会尝试..
猜你喜欢
  • 1970-01-01
  • 2022-10-08
  • 1970-01-01
  • 2017-09-23
  • 2014-09-08
  • 1970-01-01
  • 2012-10-24
  • 2012-04-17
  • 2019-06-28
相关资源
最近更新 更多