Repository: fossasia/open-event-server

Issue:
Facebook Login doesn't work
**Describe the bug**
When testing the website locally using API server also running locally, clicking on Facebook Login does not trigger anything. It doesn't show any pop-up or any error in logs or on the website.

**Expected behavior**
It should show a pop-up to ask permission for using our Facebook's info.

**Additional context**
Working on it.



Discussion:
This is not an issue I believe. You need to set the OAuth keys for this to work. 
@mrsaicharan1 Did that already. Plus, even if someone does not do that, the button shouldn't be unresponsive, it should have shown some error. 
This should be in frontend 
@iamareebjamal I think here we can discuss the implementation for the OAuth problem of Facebook. I have also opened an issue on the frontend regarding the same. 
https://github.com/fossasia/open-event-frontend/issues/2298
Ok. @mrsaicharan1 Can you please mention other people who were implementing other OAuth providers so that we can discuss? 
@uds5501 @hudda We can discuss regarding the Oauth issue here.
@mrsaicharan1 I would like to participate in workaround needed for the Oauth reconfiguration.

Resolving patch:
diff --git a/app/api/auth.py b/app/api/auth.py
--- a/app/api/auth.py
+++ b/app/api/auth.py
@@ -84,17 +84,17 @@ def get_token(provider):
     return make_response(jsonify(token=response.json()), 200)
 
 
-@auth_routes.route('/oauth/login/<provider>/<auth_code>/', methods=['GET'])
-def login_user(provider, auth_code):
+@auth_routes.route('/oauth/login/<provider>', methods=['POST'])
+def login_user(provider):
     if provider == 'facebook':
         provider_class = FbOAuth()
         payload = {
             'client_id': provider_class.get_client_id(),
-            'redirect_uri': request.args.get('redirect_uri'),
+            'redirect_uri': provider_class.get_redirect_uri(),
             'client_secret': provider_class.get_client_secret(),
-            'code': auth_code
+            'code': request.args.get('code')
         }
-        if not payload['client_id'] or payload['client_secret']:
+        if not payload['client_id'] or not payload['client_secret']:
             raise NotImplementedError({'source': ''}, 'Facebook Login Not Configured')
         access_token = requests.get('https://graph.facebook.com/v3.0/oauth/access_token', params=payload).json()
         payload_details = {
@@ -113,7 +113,7 @@ def login_user(provider, auth_code):
                 user.facebook_login_hash = random.getrandbits(128)
                 save_to_db(user)
             return make_response(
-                jsonify(user_id=user.id, email=user.email, facebook_login_hash=user.facebook_login_hash), 200)
+                jsonify(user_id=user.id, email=user.email, oauth_hash=user.facebook_login_hash), 200)
 
         user = User()
         user.first_name = user_details['first_name']
@@ -125,7 +125,7 @@ def login_user(provider, auth_code):
             user.email = user_details['email']
 
         save_to_db(user)
-        return make_response(jsonify(user_id=user.id, email=user.email, facebook_login_hash=user.facebook_login_hash),
+        return make_response(jsonify(user_id=user.id, email=user.email, oauth_hash=user.facebook_login_hash),
                              200)
 
     elif provider == 'google':
diff --git a/app/api/helpers/third_party_auth.py b/app/api/helpers/third_party_auth.py
--- a/app/api/helpers/third_party_auth.py
+++ b/app/api/helpers/third_party_auth.py
@@ -4,6 +4,7 @@
 from flask import request
 
 from app.settings import get_settings
+from app.api.helpers.files import make_frontend_url
 
 
 class GoogleOAuth(object):
@@ -59,9 +60,9 @@ def get_client_secret(cls):
 
     @classmethod
     def get_redirect_uri(cls):
-        url = urllib.parse.urlparse(request.url)
-        fb_redirect_uri = url.scheme + '://' + url.netloc + '/fCallback'
-        return fb_redirect_uri
+        url = make_frontend_url(
+            '/oauth/callback?provider=facebook')
+        return url
 
     @classmethod
     def get_auth_uri(cls):


Test patch: