如何更改GoogleOauth2 omniauth提供商名称的名称?

时间:2016-09-12 17:43:53

标签: ruby oauth omniauth

我正在使用Google Omniauth gem here并需要提供两个实例,以便我可以让他们要求一组不同的权限。我使用这个guide使用相同的Facebook gem。做同样的事情并不适用于Google gem。有谁知道我能做些什么来实现这一目标?

2 个答案:

答案 0 :(得分:0)

好的,我明白了。出于某种原因,Google Oauth2 gem不能使用提供程序名称作为符号,但会使用类名。所以我能用这个来解决这个问题:

# initializers/omniauth.rb
module OmniAuth::Strategies
  class GoogleIntegration < GoogleOauth2
  end
end

Rails.application.config.middleware.use OmniAuth::Builder do
  provider OmniAuth::Strategies::GoogleIntegration, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"],
    {
      ...
    }
end

答案 1 :(得分:0)

晚了几年,但是现在这是正确的方法:

export default function (state = initialState, action) {
  switch (action.type) {
    case GET_TRANSFUSIONS:
      return {
        ...state,
        transfusions: action.payload,
      };
    case ADD_TRANSFUSION:
      return {
        ...state,
        transfusions: [...state.transfusions, action.payload],
      };
    case UPDATE_TRANSFUSION:
      console.log(action.payload)
      return {
        ...state,
        transfusions: state.transfusions.map(
          (transfusion) => transfusion.id === action.payload.id ? {
            ...state,
            transfusion: action.payload
          } : transfusions
        ),
      };
    case DELETE_TRANSFUSION:
      return {
        ...state,
        transfusions: state.transfusions.filter(
          (transfusion) => transfusion.id !== action.payload
        ),
      };
    default:
      return state;
  }
}