omniauth-google-oauth2 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -1
- data/.travis.yml +3 -1
- data/README.md +8 -5
- data/lib/omniauth/google_oauth2/version.rb +1 -1
- data/lib/omniauth/strategies/google_oauth2.rb +9 -1
- data/spec/omniauth/strategies/google_oauth2_spec.rb +85 -7
- metadata +6 -21
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            !binary "U0hBMQ==":
         | 
| 3 | 
            +
              metadata.gz: !binary |-
         | 
| 4 | 
            +
                Nzk0NDc2ZmZhYjJiOTI1OWI5NDY1NDcwZTNlNWE2NTI0OTk1OWQwNQ==
         | 
| 5 | 
            +
              data.tar.gz: !binary |-
         | 
| 6 | 
            +
                NmMzNzgxNzg3NDAxYTE5NGI1ODc5MzA1MDY3YmI1MGNlZjc5ODlkYQ==
         | 
| 7 | 
            +
            !binary "U0hBNTEy":
         | 
| 8 | 
            +
              metadata.gz: !binary |-
         | 
| 9 | 
            +
                NWEzNjllMDY0ODRkMTY1ZTljMGYwOGQzZWI4YjE3ZWUxMGY1YWUwMjQxMjVh
         | 
| 10 | 
            +
                NDhjNTRlYzVlOWFiYWU2ZjZhYWQwMThlNzU0NmI1NzE0MTc1NGRlOTYwMjk2
         | 
| 11 | 
            +
                NTY5ZWE0Mjk4MjNiZTNkN2NmYWQ5ZmJlOWRhYWE2YjUxZDA3YWY=
         | 
| 12 | 
            +
              data.tar.gz: !binary |-
         | 
| 13 | 
            +
                NTFhODFlZDlkZDVmMTY4NzJkMzc4YzJmZGMzZjc4NTA2ZGE0Y2NhMDY0MTEx
         | 
| 14 | 
            +
                YTg5ZmU5NGZhOWFjNWIzOThiNjMxMzlkMzljMjFlZTFlNDVhYTY5NzZhY2Iz
         | 
| 15 | 
            +
                YWU5YzA4MDFiOWY5NDEyNWUxMDQxZWEzNDAzOTYwM2RlMDkzMjM=
         | 
    
        data/.ruby-gemset
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            omniauth-google-oauth2
         | 
    
        data/.ruby-version
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
             | 
| 1 | 
            +
            1.9.3-p484
         | 
    
        data/.travis.yml
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -28,7 +28,7 @@ end | |
| 28 28 |  | 
| 29 29 | 
             
            You can now access the OmniAuth Google OAuth2 URL: `/auth/google_oauth2`
         | 
| 30 30 |  | 
| 31 | 
            -
             | 
| 31 | 
            +
            For more examples please check out `examples/omni_auth.rb`
         | 
| 32 32 |  | 
| 33 33 | 
             
            ## Configuration
         | 
| 34 34 |  | 
| @@ -36,7 +36,7 @@ You can configure several options, which you pass in to the `provider` method vi | |
| 36 36 |  | 
| 37 37 | 
             
            * `scope`: A comma-separated list of permissions you want to request from the user. See the [Google OAuth 2.0 Playground](https://developers.google.com/oauthplayground/) for a full list of available permissions. Caveats:
         | 
| 38 38 | 
             
              * The `userinfo.email` and `userinfo.profile` scopes are used by default. By defining your own `scope`, you override these defaults. If you need these scopes, don't forget to add them yourself!
         | 
| 39 | 
            -
              * Scopes starting with `https://www.googleapis.com/auth/` do not need that prefix specified. So while you  | 
| 39 | 
            +
              * Scopes starting with `https://www.googleapis.com/auth/` do not need that prefix specified. So while you can use the smaller scope `books` since that permission starts with the mentioned prefix, you should use the full scope URL `https://docs.google.com/feeds/` to access a user's docs, for example.
         | 
| 40 40 | 
             
            * `prompt`: A space-delimited list of string values that determines whether the user is re-prompted for authentication and/or consent. Possible values are:
         | 
| 41 41 | 
             
              * `none`: No authentication or consent pages will be displayed; it will return an error if the user is not already authenticated and has not pre-configured consent for the requested scopes. This can be used as a method to check for existing authentication and/or consent.
         | 
| 42 42 | 
             
              * `consent`: The user will always be prompted for consent, even if he has previously allowed access a given set of scopes.
         | 
| @@ -50,16 +50,19 @@ You can configure several options, which you pass in to the `provider` method vi | |
| 50 50 |  | 
| 51 51 | 
             
              Defaults to `original`.
         | 
| 52 52 |  | 
| 53 | 
            -
            * `image_size`: The size of the user's profile picture. The image returned will have width equal to the given value and variable height, according to the `image_aspect_ratio` chosen. Additionally, a picture with specific width and height can be  | 
| 53 | 
            +
            * `image_size`: The size of the user's profile picture. The image returned will have width equal to the given value and variable height, according to the `image_aspect_ratio` chosen. Additionally, a picture with specific width and height can be requested by setting this option to a hash with `width` and `height` as keys. If only `width` or `height` is specified, a picture whose width or height is closest to the requested size and requested aspect ratio will be returned. Defaults to the original width and height of the picture.
         | 
| 54 54 |  | 
| 55 | 
            -
            * ` | 
| 55 | 
            +
            * `name`: The name of the strategy. The default name is `google_oauth2` but it can be changed to any value, for example `google`. The OmniAuth URL will thus change to `/auth/google` and the `provider` key in the auth hash will then return `google`.
         | 
| 56 56 |  | 
| 57 | 
            -
             | 
| 57 | 
            +
            * `access_type`: Defaults to `offline`, so a refresh token is sent to be used when the user is not present at the browser. Can be set to `online`. Note that if you need a refresh token, google requires you to also to specify the option `prompt: 'consent'`, which is not a default.
         | 
| 58 | 
            +
             | 
| 59 | 
            +
            Here's an example of a possible configuration where the strategy name is changed, the user is asked for extra permissions, the user is always prompted to select his account when logging in and the user's profile picture is returned as a thumbnail:
         | 
| 58 60 |  | 
| 59 61 | 
             
            ```ruby
         | 
| 60 62 | 
             
            Rails.application.config.middleware.use OmniAuth::Builder do
         | 
| 61 63 | 
             
              provider :google_oauth2, ENV["GOOGLE_KEY"], ENV["GOOGLE_SECRET"],
         | 
| 62 64 | 
             
                {
         | 
| 65 | 
            +
                  :name => "google",
         | 
| 63 66 | 
             
                  :scope => "userinfo.email, userinfo.profile, plus.me, http://gdata.youtube.com",
         | 
| 64 67 | 
             
                  :prompt => "select_account",
         | 
| 65 68 | 
             
                  :image_aspect_ratio => "square",
         | 
| @@ -8,7 +8,9 @@ module OmniAuth | |
| 8 8 |  | 
| 9 9 | 
             
                  option :name, 'google_oauth2'
         | 
| 10 10 |  | 
| 11 | 
            -
                  option : | 
| 11 | 
            +
                  option :skip_friends, true
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  option :authorize_options, [:access_type, :hd, :login_hint, :prompt, :request_visible_actions, :scope, :state, :redirect_uri]
         | 
| 12 14 |  | 
| 13 15 | 
             
                  option :client_options, {
         | 
| 14 16 | 
             
                    :site          => 'https://accounts.google.com',
         | 
| @@ -49,7 +51,9 @@ module OmniAuth | |
| 49 51 |  | 
| 50 52 | 
             
                  extra do
         | 
| 51 53 | 
             
                    hash = {}
         | 
| 54 | 
            +
                    hash[:id_token] = access_token['id_token']
         | 
| 52 55 | 
             
                    hash[:raw_info] = raw_info unless skip_info?
         | 
| 56 | 
            +
                    hash[:raw_friend_info] = raw_friend_info(raw_info['id']) unless skip_info? || options[:skip_friends]
         | 
| 53 57 | 
             
                    prune! hash
         | 
| 54 58 | 
             
                  end
         | 
| 55 59 |  | 
| @@ -57,6 +61,10 @@ module OmniAuth | |
| 57 61 | 
             
                    @raw_info ||= access_token.get('https://www.googleapis.com/oauth2/v1/userinfo').parsed
         | 
| 58 62 | 
             
                  end
         | 
| 59 63 |  | 
| 64 | 
            +
                  def raw_friend_info(id)
         | 
| 65 | 
            +
                    @raw_friend_info ||= access_token.get("https://www.googleapis.com/plus/v1/people/#{id}/people/visible").parsed
         | 
| 66 | 
            +
                  end
         | 
| 67 | 
            +
             | 
| 60 68 | 
             
                  def custom_build_access_token
         | 
| 61 69 | 
             
                    if verify_token(request.params['id_token'], request.params['access_token'])
         | 
| 62 70 | 
             
                      ::OAuth2::AccessToken.from_hash(client, request.params.dup)
         | 
| @@ -121,6 +121,17 @@ describe OmniAuth::Strategies::GoogleOauth2 do | |
| 121 121 | 
             
                  end
         | 
| 122 122 | 
             
                end
         | 
| 123 123 |  | 
| 124 | 
            +
                describe 'request_visible_actions' do
         | 
| 125 | 
            +
                  it "should default to nil" do
         | 
| 126 | 
            +
                    subject.authorize_params['request_visible_actions'].should eq(nil)
         | 
| 127 | 
            +
                  end
         | 
| 128 | 
            +
             | 
| 129 | 
            +
                  it 'should set the request_visible_actions parameter if present' do
         | 
| 130 | 
            +
                    @options = {:request_visible_actions => 'something'}
         | 
| 131 | 
            +
                    subject.authorize_params['request_visible_actions'].should eq('something')
         | 
| 132 | 
            +
                  end
         | 
| 133 | 
            +
                end
         | 
| 134 | 
            +
             | 
| 124 135 | 
             
                describe 'scope' do
         | 
| 125 136 | 
             
                  it 'should expand scope shortcuts' do
         | 
| 126 137 | 
             
                    @options = {:scope => 'userinfo.email'}
         | 
| @@ -238,15 +249,82 @@ describe OmniAuth::Strategies::GoogleOauth2 do | |
| 238 249 | 
             
                end
         | 
| 239 250 | 
             
              end
         | 
| 240 251 |  | 
| 241 | 
            -
              describe ' | 
| 242 | 
            -
                 | 
| 243 | 
            -
                   | 
| 244 | 
            -
             | 
| 252 | 
            +
              describe '#extra' do
         | 
| 253 | 
            +
                let(:client) do
         | 
| 254 | 
            +
                  OAuth2::Client.new('abc', 'def') do |builder|
         | 
| 255 | 
            +
                    builder.request :url_encoded
         | 
| 256 | 
            +
                    builder.adapter :test do |stub|
         | 
| 257 | 
            +
                      stub.get('/oauth2/v1/userinfo') {|env| [200, {'content-type' => 'application/json'}, '{"id": "12345"}']}
         | 
| 258 | 
            +
                      stub.get('/plus/v1/people/12345/people/visible') {|env| [200, {'content-type' => 'application/json'}, '[{"foo":"bar"}]']}
         | 
| 259 | 
            +
                    end
         | 
| 260 | 
            +
                  end
         | 
| 261 | 
            +
                end
         | 
| 262 | 
            +
                let(:access_token) { OAuth2::AccessToken.from_hash(client, {}) }
         | 
| 263 | 
            +
             | 
| 264 | 
            +
                before { subject.stub(:access_token => access_token) }
         | 
| 265 | 
            +
             | 
| 266 | 
            +
                describe 'id_token' do
         | 
| 267 | 
            +
                  context 'when the id_token is passed into the access token' do
         | 
| 268 | 
            +
                   let(:access_token) { OAuth2::AccessToken.from_hash(client, {'id_token' => 'xyz'}) }
         | 
| 269 | 
            +
             | 
| 270 | 
            +
                    it 'should include id_token when set on the access_token' do
         | 
| 271 | 
            +
                      subject.extra.should include(:id_token => 'xyz')
         | 
| 272 | 
            +
                    end
         | 
| 273 | 
            +
                  end
         | 
| 274 | 
            +
             | 
| 275 | 
            +
                  context 'when the id_token is missing' do
         | 
| 276 | 
            +
                    it 'should not include id_token' do
         | 
| 277 | 
            +
                      subject.extra.should_not have_key(:id_token)
         | 
| 278 | 
            +
                    end
         | 
| 279 | 
            +
                  end
         | 
| 280 | 
            +
                end
         | 
| 281 | 
            +
             | 
| 282 | 
            +
                describe 'raw_info' do
         | 
| 283 | 
            +
                  context 'when skip_info is true' do
         | 
| 284 | 
            +
                    before { subject.options[:skip_info] = true }
         | 
| 285 | 
            +
             | 
| 286 | 
            +
                    it 'should not include raw_info' do
         | 
| 287 | 
            +
                      subject.extra.should_not have_key(:raw_info)
         | 
| 288 | 
            +
                    end
         | 
| 289 | 
            +
                  end
         | 
| 290 | 
            +
             | 
| 291 | 
            +
                  context 'when skip_info is false' do
         | 
| 292 | 
            +
                    before { subject.options[:skip_info] = false }
         | 
| 293 | 
            +
             | 
| 294 | 
            +
                    it 'should include raw_info' do
         | 
| 295 | 
            +
                      subject.extra[:raw_info].should eq('id' => '12345')
         | 
| 296 | 
            +
                    end
         | 
| 297 | 
            +
                  end
         | 
| 245 298 | 
             
                end
         | 
| 246 299 |  | 
| 247 | 
            -
                 | 
| 248 | 
            -
                   | 
| 249 | 
            -
             | 
| 300 | 
            +
                describe 'raw_friend_info' do
         | 
| 301 | 
            +
                  context 'when skip_info is true' do
         | 
| 302 | 
            +
                    before { subject.options[:skip_info] = true }
         | 
| 303 | 
            +
             | 
| 304 | 
            +
                    it 'should not include raw_friend_info' do
         | 
| 305 | 
            +
                      subject.extra.should_not have_key(:raw_friend_info)
         | 
| 306 | 
            +
                    end
         | 
| 307 | 
            +
                  end
         | 
| 308 | 
            +
             | 
| 309 | 
            +
                  context 'when skip_info is false' do
         | 
| 310 | 
            +
                    before { subject.options[:skip_info] = false }
         | 
| 311 | 
            +
             | 
| 312 | 
            +
                    context 'when skip_friends is true' do
         | 
| 313 | 
            +
                      before { subject.options[:skip_friends] = true }
         | 
| 314 | 
            +
             | 
| 315 | 
            +
                      it 'should not include raw_friend_info' do
         | 
| 316 | 
            +
                        subject.extra.should_not have_key(:raw_friend_info)
         | 
| 317 | 
            +
                      end
         | 
| 318 | 
            +
                    end
         | 
| 319 | 
            +
             | 
| 320 | 
            +
                    context 'when skip_friends is false' do
         | 
| 321 | 
            +
                      before { subject.options[:skip_friends] = false }
         | 
| 322 | 
            +
             | 
| 323 | 
            +
                      it 'should not include raw_friend_info' do
         | 
| 324 | 
            +
                        subject.extra[:raw_friend_info].should eq([{'foo' => 'bar'}])
         | 
| 325 | 
            +
                      end
         | 
| 326 | 
            +
                    end
         | 
| 327 | 
            +
                  end
         | 
| 250 328 | 
             
                end
         | 
| 251 329 | 
             
              end
         | 
| 252 330 |  | 
    
        metadata
    CHANGED
    
    | @@ -1,8 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: omniauth-google-oauth2
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 5 | 
            -
              prerelease: 
         | 
| 4 | 
            +
              version: 0.2.2
         | 
| 6 5 | 
             
            platform: ruby
         | 
| 7 6 | 
             
            authors:
         | 
| 8 7 | 
             
            - Josh Ellithorpe
         | 
| @@ -10,12 +9,11 @@ authors: | |
| 10 9 | 
             
            autorequire: 
         | 
| 11 10 | 
             
            bindir: bin
         | 
| 12 11 | 
             
            cert_chain: []
         | 
| 13 | 
            -
            date: 2013- | 
| 12 | 
            +
            date: 2013-12-31 00:00:00.000000000 Z
         | 
| 14 13 | 
             
            dependencies:
         | 
| 15 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 16 15 | 
             
              name: omniauth
         | 
| 17 16 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 18 | 
            -
                none: false
         | 
| 19 17 | 
             
                requirements:
         | 
| 20 18 | 
             
                - - ~>
         | 
| 21 19 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -23,7 +21,6 @@ dependencies: | |
| 23 21 | 
             
              type: :runtime
         | 
| 24 22 | 
             
              prerelease: false
         | 
| 25 23 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 26 | 
            -
                none: false
         | 
| 27 24 | 
             
                requirements:
         | 
| 28 25 | 
             
                - - ~>
         | 
| 29 26 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -31,7 +28,6 @@ dependencies: | |
| 31 28 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 32 29 | 
             
              name: omniauth-oauth2
         | 
| 33 30 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 34 | 
            -
                none: false
         | 
| 35 31 | 
             
                requirements:
         | 
| 36 32 | 
             
                - - ! '>='
         | 
| 37 33 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -39,7 +35,6 @@ dependencies: | |
| 39 35 | 
             
              type: :runtime
         | 
| 40 36 | 
             
              prerelease: false
         | 
| 41 37 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 42 | 
            -
                none: false
         | 
| 43 38 | 
             
                requirements:
         | 
| 44 39 | 
             
                - - ! '>='
         | 
| 45 40 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -47,7 +42,6 @@ dependencies: | |
| 47 42 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 48 43 | 
             
              name: rspec
         | 
| 49 44 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 50 | 
            -
                none: false
         | 
| 51 45 | 
             
                requirements:
         | 
| 52 46 | 
             
                - - ~>
         | 
| 53 47 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -55,7 +49,6 @@ dependencies: | |
| 55 49 | 
             
              type: :development
         | 
| 56 50 | 
             
              prerelease: false
         | 
| 57 51 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 58 | 
            -
                none: false
         | 
| 59 52 | 
             
                requirements:
         | 
| 60 53 | 
             
                - - ~>
         | 
| 61 54 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -63,7 +56,6 @@ dependencies: | |
| 63 56 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 64 57 | 
             
              name: rake
         | 
| 65 58 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 66 | 
            -
                none: false
         | 
| 67 59 | 
             
                requirements:
         | 
| 68 60 | 
             
                - - ! '>='
         | 
| 69 61 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -71,7 +63,6 @@ dependencies: | |
| 71 63 | 
             
              type: :development
         | 
| 72 64 | 
             
              prerelease: false
         | 
| 73 65 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 74 | 
            -
                none: false
         | 
| 75 66 | 
             
                requirements:
         | 
| 76 67 | 
             
                - - ! '>='
         | 
| 77 68 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -84,6 +75,7 @@ extensions: [] | |
| 84 75 | 
             
            extra_rdoc_files: []
         | 
| 85 76 | 
             
            files:
         | 
| 86 77 | 
             
            - .gitignore
         | 
| 78 | 
            +
            - .ruby-gemset
         | 
| 87 79 | 
             
            - .ruby-version
         | 
| 88 80 | 
             
            - .rvmrc
         | 
| 89 81 | 
             
            - .travis.yml
         | 
| @@ -101,32 +93,25 @@ files: | |
| 101 93 | 
             
            - spec/spec_helper.rb
         | 
| 102 94 | 
             
            homepage: ''
         | 
| 103 95 | 
             
            licenses: []
         | 
| 96 | 
            +
            metadata: {}
         | 
| 104 97 | 
             
            post_install_message: 
         | 
| 105 98 | 
             
            rdoc_options: []
         | 
| 106 99 | 
             
            require_paths:
         | 
| 107 100 | 
             
            - lib
         | 
| 108 101 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 109 | 
            -
              none: false
         | 
| 110 102 | 
             
              requirements:
         | 
| 111 103 | 
             
              - - ! '>='
         | 
| 112 104 | 
             
                - !ruby/object:Gem::Version
         | 
| 113 105 | 
             
                  version: '0'
         | 
| 114 | 
            -
                  segments:
         | 
| 115 | 
            -
                  - 0
         | 
| 116 | 
            -
                  hash: -775688096927888860
         | 
| 117 106 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 118 | 
            -
              none: false
         | 
| 119 107 | 
             
              requirements:
         | 
| 120 108 | 
             
              - - ! '>='
         | 
| 121 109 | 
             
                - !ruby/object:Gem::Version
         | 
| 122 110 | 
             
                  version: '0'
         | 
| 123 | 
            -
                  segments:
         | 
| 124 | 
            -
                  - 0
         | 
| 125 | 
            -
                  hash: -775688096927888860
         | 
| 126 111 | 
             
            requirements: []
         | 
| 127 112 | 
             
            rubyforge_project: 
         | 
| 128 | 
            -
            rubygems_version:  | 
| 113 | 
            +
            rubygems_version: 2.0.7
         | 
| 129 114 | 
             
            signing_key: 
         | 
| 130 | 
            -
            specification_version:  | 
| 115 | 
            +
            specification_version: 4
         | 
| 131 116 | 
             
            summary: A Google OAuth2 strategy for OmniAuth 1.x
         | 
| 132 117 | 
             
            test_files: []
         |