Skip to content

Commit

Permalink
Merge pull request #982 from pmrowla/flickr-auth-params
Browse files Browse the repository at this point in the history
Allow user to specify extra auth parameters for Flickr (and generic OAuth) providers
  • Loading branch information
pennersr committed Jun 27, 2015
2 parents bdce50f + eb5d237 commit bb85357
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
7 changes: 7 additions & 0 deletions allauth/socialaccount/providers/flickr/provider.py
Expand Up @@ -28,6 +28,13 @@ def get_default_scope(self):
scope = []
return scope

def get_auth_params(self, request, action):
ret = super(FlickrProvider, self).get_auth_params(request,
action)
if 'perms' not in ret:
ret['perms'] = 'read'
return ret

def get_profile_fields(self):
default_fields = ['id',
'first-name',
Expand Down
3 changes: 2 additions & 1 deletion allauth/socialaccount/providers/oauth/client.py
Expand Up @@ -133,7 +133,7 @@ def is_valid(self):
return False
return True

def get_redirect(self, authorization_url):
def get_redirect(self, authorization_url, extra_params):
"""
Returns a ``HttpResponseRedirect`` object to redirect the user
to the URL the OAuth provider handles authorization.
Expand All @@ -142,6 +142,7 @@ def get_redirect(self, authorization_url):
params = {'oauth_token': request_token['oauth_token'],
'oauth_callback': self.request.build_absolute_uri(
self.callback_url)}
params.update(extra_params)
url = authorization_url + '?' + urlencode(params)
return HttpResponseRedirect(url)

Expand Down
13 changes: 13 additions & 0 deletions allauth/socialaccount/providers/oauth/provider.py
@@ -1,3 +1,8 @@
try:
from urllib.parse import parse_qsl
except ImportError:
from urlparse import parse_qsl

from django.core.urlresolvers import reverse
from django.utils.http import urlencode

Expand All @@ -12,6 +17,14 @@ def get_login_url(self, request, **kwargs):
url = url + '?' + urlencode(kwargs)
return url

def get_auth_params(self, request, action):
settings = self.get_settings()
ret = settings.get('AUTH_PARAMS', {})
dynamic_auth_params = request.GET.get('auth_params', None)
if dynamic_auth_params:
ret.update(dict(parse_qsl(dynamic_auth_params)))
return ret

def get_auth_url(self, request, action):
# TODO: This is ugly. Move authorization_url away from the
# adapter into the provider. Hmpf, the line between
Expand Down
3 changes: 2 additions & 1 deletion allauth/socialaccount/providers/oauth/views.py
Expand Up @@ -57,9 +57,10 @@ def dispatch(self, request):
provider = self.adapter.get_provider()
auth_url = provider.get_auth_url(request,
action) or self.adapter.authorize_url
auth_params = provider.get_auth_params(request, action)
client = self._get_client(request, callback_url)
try:
return client.get_redirect(auth_url)
return client.get_redirect(auth_url, auth_params)
except OAuthError as e:
return render_authentication_error(request,
self.adapter.provider_id,
Expand Down
16 changes: 16 additions & 0 deletions docs/providers.rst
Expand Up @@ -143,6 +143,22 @@ The provider is OAuth2 based. More info:

Note: This is not the same as the Mozilla Persona provider below.

Flickr
------

App registration
https://www.flickr.com/services/apps/create/

You can optionally specify the application permissions to use. If no `perms`
value is set, the Flickr provider will use `read` by default.::

SOCIALACCOUNT_PROVIDERS = \
{ 'flickr':
{ 'AUTH_PARAMS': { 'perms': 'write' } }}

More info:
https://www.flickr.com/services/api/auth.oauth.html#authorization

GitHub
------

Expand Down

0 comments on commit bb85357

Please sign in to comment.