首页 > 解决方案 > Spring Security 和 Grails - 为 Heroku 自定义 URL

问题描述

我正在使用以下插件:https ://github.com/MatrixCrawler/grails-spring-security-oauth2

我在我的 application.yml 中以这种方式配置它:

grails:
  plugin:
    springsecurity:
        oauth2:
            active: true
            domainClass: 'myapp.OAuthID'
            providers:
                google:
                    api_key: '...'
                    api_secret: '...'

它在 localhost 中运行良好,但是当我在 Heroku 中部署我的项目时,使用 Google 登录的按钮在 localhost 环境中返回一个回调。为什么?我不知道。

我会在浏览器中看到 Google 帐户,但是当我点击任何帐户时,服务器会重定向到http://localhost:8080/ ...

我认为这个问题是由于 Procfile 文件或插件配置造成的。如何解决这个问题?

过程文件

web: cd build ; java $JAVA_OPTS -Xmx256m -Dgrails.env=prod -jar ../build/server/webapp-runner-*.jar --expand-war --port $PORT libs/*.war

标签: springherokugrailsgoogle-oauthgrails-plugin

解决方案


我只需要将服务器 URL 添加到配置文件中,如下所示:

grails:
   serverURL: ${HOST_NAME}

HOST_NAME 是一个环境变量。


推荐阅读