def auth_up(req): # pragma: no cover """ ``GET`` @ |ta| ``/auth/<provider>/<token>`` This function handles the authentication via password and username """ j_req = json_from_request(req, ['username', 'password']) username = j_req['username'] password = j_req['password'] auth_id = "gc:" + username try: user = User.get_by_auth_password(auth_id, password) except: raise AuthenticationError("Username or password are invalid") s_token = GCAuth.auth_user_token(user) # if we crate the response, then we need the cors stuff. # response = webapp2.Response(content_type='application/json', charset='UTF-8') # if created: # response.status = 201 # cookie = GCAuth.get_secure_cookie(token) # response.set_cookie('gc_token', cookie, secure=False, # max_age=int(cfg.AUTH_TOKEN_MAX_AGE), domain="/") token = GCAuth.get_token(s_token) # resp.headers.update({ # 'Access-Control-Allow-Origin': origin, # 'Access-Control-Allow-Credentials': 'true'}) # response.write(json.dumps(token)) deferred.defer(sync_user, user, s_token) return token
def authenticate(self, auth_id=None, password=None): """Support logging in as a normal user""" user = User.get_by_auth_password(auth_id, password) if user is None: return None