How to config image size returned using omniauth-google-oauth2?

雨燕双飞 提交于 2019-12-23 01:36:20

问题


I try to config the omniauth-google-oauth2 with devise in my Rails app:

config.omniauth :google_oauth2, GOOGLE_APP_ID, GOOGLE_APP_SECRET, {
    scope: 'email, profile, plus.login',
    provider_ignores_state: true,
    prompt: 'select_account',
    image_aspect_ratio: 'square',
    image_size: 50,
    skip_jwt: true
}

This work but I try to config the image_size to be larger:

image_size: 100,

or

image_size: {width: 100, height: 100}, 

Based on this documentation, and it doesn't work, it always returns the image url like https://lh4.googleusercontent.com/-zE4TdSazXvI/AAAAAAAAAAI/AAAAAAAAACA/jWRW9BtDAlU/s128-c/photo.jpg?sz=50

This issue was raised at Rails devise with omniauth-google-oauth2 image size does not work as well, but no result on that!

Don't tell me to write this kind of hard code:

url = "https://lh4.googleusercontent.com/-zE4TdSazXvI/AAAAAAAAAAI/AAAAAAAAACA/jWRW9BtDAlU/s128-c/photo.jpg?sz=50"
url = url.sub('?sz=50', '?sz=100')

Is there another way to achieve this?


回答1:


There was an issue on Github about this. The fix is implemented in the new gems. For me it helped to simply update the omniauth-google-oauth2 gem to a version >0.2.6.

Try bundle update omniauth-google-oauth2 or define a specific version in your Gemfile:

gem "omniauth-google-oauth2", "~> 0.4.1"


来源:https://stackoverflow.com/questions/37375666/how-to-config-image-size-returned-using-omniauth-google-oauth2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!