samvera / browse-everything

Rails engine providing access to files in cloud storage
Apache License 2.0
113 stars 22 forks source link

Implement the Dropbox Driver for 2.0.0 #321

Open jrgriffiniii opened 4 years ago

jrgriffiniii commented 4 years ago

This should draw heavily from https://rubygems.org/gems/dropbox_api

jrgriffiniii commented 4 years ago

Authorization with OAuth2 for the API was a bit complex, but the general pattern is as follows:

Currently, https://github.com/samvera/browse-everything/blob/2.x-stable/app/serializers/provider_serializer.rb#L9 references https://github.com/samvera/browse-everything/blob/2.x-stable/lib/browse_everything/provider/google_drive.rb#L34 in Google Drive to provide the OAuth2 authorization URL for clients. Providing a Dropbox#authorization_url is where I would start when it comes to supporting authorization.

jrgriffiniii commented 4 years ago

https://www.rubydoc.info/gems/dropbox_api/DropboxApi/Authenticator is what I was using for this on 1.0.z releases. This appears to just wrap https://www.rubydoc.info/github/oauth-xx/oauth2/OAuth2/Client - so maybe https://www.rubydoc.info/github/oauth-xx/oauth2/OAuth2/Client#authorize_url-instance_method can be used?

jrgriffiniii commented 4 years ago

DropboxApi::Authenticator just needs to be constructed with DropboxApi::Authenticator.new(config[:client_id], config[:client_secret]) where one has something like this implemented for Dropbox#config:

        def config
          values = BrowseEverything.config['dropbox'] || {
            client_id: nil,
            client_secret: nil
          }

          OpenStruct.new(values)
        end

So, then one could implement:

def authenticator
  @authenticator ||= DropboxApi::Authenticator.new(config[:client_id], config[:client_secret])
end

def authorization_url
  authenticator.authorize_url
end