Skip to content

Instantly share code, notes, and snippets.

@asalkey
Last active October 20, 2015 02:42
Show Gist options
  • Save asalkey/c476a30aebe9c8532da3 to your computer and use it in GitHub Desktop.
Save asalkey/c476a30aebe9c8532da3 to your computer and use it in GitHub Desktop.
Sentinel social basecamp controller
<?php
protected function oauth_url()
{
$callback = URL::to('oauth/callback');
$url = SentinelSocial::getAuthorizationUrl('basecamp', $callback);
return Redirect::to($url . '&type=web_server');
}
protected function oauth_callback()
{
// Callback is required for providers such as Facebook and a few others (it's required
// by the spec, but some providers omit this).
$callback = URL::current();
try
{
$user = SentinelSocial::authenticate('basecamp', URL::current(), function(Cartalyst\SentinelSocial\Links\LinkInterface $link, $provider, $token, $slug)
{
// Retrieve the user in question for modificiation
$user = $link->getUser();
// You could add your custom data
$data = $provider->getUserDetails($token);
$user->email = $data->email;
$user->first_name = $data->firstName;
$user->last_name = $data->lastName;
$user->save();
});
}
catch (Cartalyst\SentinelSocial\AccessMissingException $e)
{
// Missing OAuth parameters were missing from the query string.
// Either the person rejected the app, or the URL has been manually
// accesed.
if ($error = Input::get('error'))
{
return Redirect::to('oauth')->withErrors($error);
}
App::abort(404);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment