Repository: pennersr/django-allauth

Issue:
ORCID provider: choose between endpoints
The ORCID platform provides three distinct OAuth2 endpoints and it would be useful to be able to choose between them without changing the code of django-allauth. (For now the URLs are hardcoded in allauth/socialaccount/providers/orcid/views.py).

The endpoints are:
http://pub.orcid.org/
http://api.orcid.org/
http://api.sandbox.orcid.org/

What is the right way to do this? Duplicate the provider for the three different endpoints? Add a dropdown menu in the admin interface to choose between the endpoints? (How?) With sufficient pointers, I can provide a pull request.

Note: the first API endpoint require a small change in the code, as explained in the documentation:
http://django-allauth.readthedocs.org/en/latest/providers.html#orcid



Discussion:
I went for the duplication, the code is here http://github.com/wetneb/django-allauth.

There will only be one endpoint in use right? If so, then how about simply adding support for picking up the endpoint from the existing setting:

```
SOCIALACCOUNT_PROVIDERS = { 'orcid': { 'ENDPOINT': 'http://api.sandbox.orcid.org' } }
```

Ideally I'd like to be able to use both in the same app, but that's already interesting, I'll try to do that and send a PR soon.


Resolving patch:
diff --git a/allauth/socialaccount/providers/orcid/views.py b/allauth/socialaccount/providers/orcid/views.py
--- a/allauth/socialaccount/providers/orcid/views.py
+++ b/allauth/socialaccount/providers/orcid/views.py
@@ -1,5 +1,6 @@
 import requests
 
+from allauth.socialaccount import app_settings
 from allauth.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                           OAuth2LoginView,
                                                           OAuth2CallbackView)
@@ -10,13 +11,28 @@ class OrcidOAuth2Adapter(OAuth2Adapter):
     provider_id = OrcidProvider.id
     # http://support.orcid.org/knowledgebase/articles/335483-the-public-
     # client-orcid-api
-    authorize_url = 'https://orcid.org/oauth/authorize'
-    access_token_url = 'https://pub.orcid.org/oauth/token'
-    profile_url = 'https://pub.orcid.org/v1.1/%s/orcid-profile'
+    
+    member_api_default = False
+    base_domain_default = 'orcid.org'
+
+    settings = app_settings.PROVIDERS.get(provider_id, {})
+
+    base_domain = settings.get('BASE_DOMAIN', base_domain_default)
+    member_api = settings.get('MEMBER_API', member_api_default)
+
+    api_domain = '{0}.{1}'.format('api' if member_api else 'pub', base_domain)
+
+    authorize_url = 'https://{0}/oauth/authorize'.format(base_domain)
+    access_token_url = 'https://{0}/oauth/token'.format(api_domain)
+    profile_url = 'https://{0}/v1.1/%s/orcid-profile'.format(api_domain)
 
     def complete_login(self, request, app, token, **kwargs):
+        params = {}
+        if self.member_api:
+            params['access_token'] = token.token
+
         resp = requests.get(self.profile_url % kwargs['response']['orcid'],
-                            params={'access_token': token.token},
+                            params=params,
                             headers={'accept': 'application/orcid+json'})
         extra_data = resp.json()
         return self.get_provider().sociallogin_from_response(request,


Test patch: