【问题标题】:Decoupled Github Oauth2 through a rails server from a chrome extension通过 Rails 服务器将 Github Oauth2 与 chrome 扩展解耦
【发布时间】:2015-11-16 13:11:30
【问题描述】:

我正在尝试从我的 chrome 扩展程序执行 Github Oauth2,但我没有使用 chrome.identity.launchWebAuthFlow,而是尝试通过我的服务器执行此操作,因此我不必将我的客户端 ID 和客户端密码放入 javascript我的 chrome 扩展。我打算这样做的方式是我对我的 Rails 服务器使用 ajax 调用

$.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 和密钥对用户隐藏。任何帮助将不胜感激。

【问题讨论】:

  • 如果您自己解决问题,请将解决方案作为答案发布,而不是作为对问题的编辑。我们没有从问题列表中看到问题已得到解决。

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


【解决方案1】:

我想通了:

问题是我没有意识到我正在尝试发送 HTTParty 对象而不是字符串,所以我必须先 @github_login_html.to_s 才能发送它。

但是,它仍然会无缘无故地进入失败功能,所以如果有人对为什么会发生这种情况有任何想法,我很想听听他们的意见。

【讨论】:

    猜你喜欢
    • 2016-06-14
    • 2016-04-30
    • 2016-04-23
    • 2015-07-21
    • 1970-01-01
    • 2021-10-18
    • 2017-01-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多