Skip to content

Commit

Permalink
Release ready
Browse files Browse the repository at this point in the history
  • Loading branch information
t1mmen committed Nov 1, 2014
1 parent ade4798 commit 81d7ae5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 30 deletions.
27 changes: 8 additions & 19 deletions DropboxStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DropboxStrategy extends OpauthStrategy {
* Auth request
*/
public function request() {
$url = 'https://api.dropboxapp.com/oauth2/authorize';
$url = 'https://www.dropbox.com/1/oauth2/authorize';
$params = array(
'client_id' => $this->strategy['client_id'],
'redirect_uri' => $this->strategy['redirect_uri'],
Expand All @@ -61,12 +61,12 @@ public function request() {
public function oauth2callback() {
if (array_key_exists('code', $_GET) && !empty($_GET['code'])) {
$code = $_GET['code'];
$url = 'https://api.dropboxapp.com/oauth2/token';
$url = 'https://api.dropbox.com/1/oauth2/token';

$params = array(
'code' => $code,
'client_id' => $this->strategy['client_id'],
'client_secret' => $this->strategy['client_secret'],
'code' => $code,
'redirect_uri' => $this->strategy['redirect_uri'],
'grant_type' => 'authorization_code',
);
Expand All @@ -80,23 +80,16 @@ public function oauth2callback() {
$user = $this->user($results['access_token']);

$this->auth = array(
'uid' => $user['user']['id'],
'info' => array(
'name' => $user['user']['first_name'].' '.$user['user']['last_name'],
'image' => $user['company']['base_uri'].$user['user']['avatar_url'],
),
'uid' => $user['uid'],
'info' => array(),
'credentials' => array(
'token' => $results['access_token'],
'refresh_token' => $results['refresh_token'],
'expires_in' => $results['expires_in'],
),
'raw' => $user
);

$this->mapProfile($user, 'user.first_name', 'info.first_name'); // look into setting full name here
$this->mapProfile($user, 'user.last_name', 'info.last_name');
$this->mapProfile($user, 'user.email', 'info.email');
$this->mapProfile($user, 'company.base_uri', 'info.urls.base_uri');
$this->mapProfile($user, 'display_name', 'info.name'); // look into setting full name here
$this->mapProfile($user, 'email', 'info.email');

$this->callback();
}
Expand Down Expand Up @@ -126,16 +119,12 @@ public function oauth2callback() {
/**
* Queries Dropbox API for user info
*
* @link https://github.com/dropboxhq/api/blob/master/Authentication/OAuth%202.0.md#for-server-side-applications
* @param string $access_token
* @return array Parsed JSON results
*/
private function user($access_token) {

$options['http']['header'] = "Content-Type: application/json";
$options['http']['header'] .= "\r\nAccept: application/json";

$user = $this->serverGet('https://api.dropboxapp.com/account/who_am_i', array('access_token' => $access_token), $options, $headers);
$user = $this->serverGet('https://api.dropbox.com/1/account/info', array('access_token' => $access_token), null, $headers);

if (!empty($user)) {
return $this->recursiveGetObjectVars(json_decode($user));
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
Opauth-Harvest
Opauth-Dropbox
=============
[Opauth][1] strategy for Harvest authentication.
[Opauth][1] strategy for Dropbox authentication.

Implemented based on https://github.com/harvesthq/api
Implemented based on https://www.dropbox.com/developers/blog/45/using-oauth-20-with-the-core-api

Getting started
----------------
1. Install Opauth-Harvest:
1. Install Opauth-Dropbox:

Using git:
```bash
cd path_to_opauth/Strategy
git clone https://github.com/t1mmen/opauth-harvest.git Harvest
git clone https://github.com/t1mmen/opauth-dropbox.git Dropbox
```

Or, using [Composer](https://getcomposer.org/), just add this to your `composer.json`:

```bash
{
"require": {
"t1mmen/opauth-harvest": "*"
"t1mmen/opauth-dropbox": "*"
}
}
```
Then run `composer install`.


2. Create Harvest application at https://platform.harvestapp.com/oauth2_clients
2. Create Dropbox application at https://www.dropbox.com/developers

3. Configure Opauth-Harvest strategy with at least `Client ID` and `Client Secret`.
3. Configure Opauth-Dropbox strategy with at least `Client ID` and `Client Secret`.

4. Direct user to `http://path_to_opauth/harvest` to authenticate
4. Direct user to `http://path_to_opauth/dropbox` to authenticate

Strategy configuration
----------------------
Expand All @@ -39,15 +39,15 @@ Required parameters:

```php
<?php
'Harvest' => array(
'Dropbox' => array(
'client_id' => 'YOUR CLIENT ID',
'client_secret' => 'YOUR CLIENT SECRET'
)
```

License
---------
Opauth-Harvest is MIT Licensed
Opauth-Dropbox is MIT Licensed
Copyright © 2014 Timm Stokke (http://timm.stokke.me)

[1]: https://github.com/opauth/opauth

0 comments on commit 81d7ae5

Please sign in to comment.