通过Chrome扩展程序

时间:2015-08-22 19:12:00

标签: javascript ruby-on-rails ajax google-chrome-extension oauth

我正在尝试从我的chrome扩展程序中执行Github Oauth2但不使用chrome.identity.launchWebAuthFlow我试图通过我的服务器执行此操作,因此我不必将我的客户端ID和客户端密钥放在javascript中我的铬扩展。我计划这样做的方式是我使用ajax调用我的rails服务器

$.ajax({
  type: 'POST',
  url: 'http://localhost:3000/github-api/login-html',
  crossDomain: true,
}).done(function(response){
  debugger
  console.log("done")
}).fail(function(error) {
  debugger
  console.log( "error" );
}).always(function() {
  console.log( "always" );
});

然后从那里向登录页面的github发出Oauth请求:

def login_html
    @github_login_html = HTTParty.get('https://github.com/login/oauth/authorize?client_id=697d344740e266bf7a02&redirect_uri=http://localhost:3000/')
    bingind.pry
    render json: @github_login_html
end

并且基本上将其转发回chrome扩展程序,并在Chrome扩展程序触发的弹出窗口中将其呈现给用户。

我的问题是@github_login_html正是我需要它在#login_html的binding.pry中,但当它返回到ajax请求时它会触发.fail函数并且响应文本是

"serverdatecontent-typetransfer-encodingconnectionstatuscontent-security-policypublic-key-pinscache-controlvaryx-ua-compatibleset-cookiex-request-idx-runtimex-github-request-idstrict-transport-securityx-content-type-optionsx-xss-protectionx-frame-optionsx-served-b"

但它的状态为200,statusText为" OK"。

不确定是什么导致了这种或其他方式我可以去做Oauth,这会让我的客户ID和密钥对用户隐藏起来。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

我明白了:

问题是我没有意识到我试图发送HTTParty对象而不是字符串所以我必须在发送之前做@ github_login_html.to_s。

然而,由于没有明显的理由,它仍然会失败,所以如果有人对于为什么会发生这种情况有任何想法我会很乐意听到它们。

相关问题