Open jrgriffiniii opened 4 years ago
Authorization with OAuth2 for the API was a bit complex, but the general pattern is as follows:
Authorization
in RailsCurrently, 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.
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?
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
This should draw heavily from https://rubygems.org/gems/dropbox_api