【问题标题】:Google oauth blocked in local developmentGoogle oauth 在本地开发中被阻止
【发布时间】:2014-08-27 22:36:33
【问题描述】:

我正在使用 rails/ember 应用程序中的omniauth,并且在使用 google 登录时遇到了一些问题。我收到了弹出窗口以允许网站对我进行身份验证,但是在单击之后接受请求炸弹:

Uncaught SecurityError: Blocked a frame with origin "https://localhost:3001" from 
accessing a frame with origin "https://accounts.google.com". Protocols, domains, 
and ports must match. 

我在本地开发中使用自签名证书获取 HTTPS,但如何在本地测试此身份验证逻辑?

Coffeescript 尝试登录:

$ ->
  $.ajax
    url: '//apis.google.com/js/client:plus.js?onload=gpAsyncInit'
    dataType: 'script'
    cache: true
window.gpAsyncInit = ->
  $(".google-login").click (e) ->
    e.preventDefault()
    gapi.auth.authorize
      immediate: false
      response_type: "code"
      client_id: "<%= ENV["GOOGLE_CLIENT_ID"] %>"
      scope: "email profile"
    , (response) ->
      if response and not response.error
        jQuery.ajax
          type: "POST"
          url: "/auth/google_oauth2/callback"
          dataType: "json"
          data: response
          success: (json) ->
            alert 'success!'
      else
        alert response.error

【问题讨论】:

    标签: ruby-on-rails coffeescript oauth-2.0 google-oauth


    【解决方案1】:

    尝试将 localhost 替换为有效域,例如。 mydevserver.me.com。您可以将 mydevserver.me.com 指向 /etc/hosts 中的 127.0.0.1。您还需要将 http://mydevserver.me.com/mycallback 作为回调 url 添加到 Google API 控制台

    【讨论】:

      猜你喜欢
      • 2011-01-25
      • 1970-01-01
      • 2018-06-29
      • 1970-01-01
      • 1970-01-01
      • 2020-03-16
      • 1970-01-01
      • 2014-08-02
      • 1970-01-01
      相关资源
      最近更新 更多