예제 #1
0
def authreturn(req, service, level=None):
    if ("error" in req.GET or "not_approved" in req.GET):
        success = False
    else:
        svc = Service.FromID(service)
        try:
            uid, authData = svc.RetrieveAuthorizationToken(req, level)
        except Exception as e:
            return render(req, "oauth-failure.html", {
                "service": svc,
                "error": str(e)
            })
        serviceRecord = Service.EnsureServiceRecordWithAuth(svc, uid, authData)

        # auth by this service connection
        existingUser = User.AuthByService(serviceRecord)
        # only log us in as this different user in the case that we don't already have an account
        if req.user is None and existingUser is not None:
            User.Login(existingUser, req)
        else:
            User.Ensure(req)
        # link service to user account, possible merge happens behind the scenes (but doesn't effect active user)
        User.ConnectService(req.user, serviceRecord)
        success = True

    return render(req, "oauth-return.html", {"success": 1 if success else 0})
예제 #2
0
파일: auth.py 프로젝트: ctrlbreak/tapiriik
def auth_do(req, service):
    svc = Service.FromID(service)
    from tapiriik.services.api import APIException
    try:
        if svc.RequiresExtendedAuthorizationDetails:
            uid, authData, extendedAuthData = svc.Authorize(
                req.POST["username"], req.POST["password"])
        else:
            uid, authData = svc.Authorize(req.POST["username"],
                                          req.POST["password"])
    except APIException:
        return False
    if authData is not None:
        serviceRecord = Service.EnsureServiceRecordWithAuth(
            svc,
            uid,
            authData,
            extendedAuthDetails=extendedAuthData
            if svc.RequiresExtendedAuthorizationDetails else None,
            persistExtendedAuthDetails=bool(req.POST.get("persist", None)))
        # auth by this service connection
        existingUser = User.AuthByService(serviceRecord)
        # only log us in as this different user in the case that we don't already have an account
        if existingUser is not None and req.user is None:
            User.Login(existingUser, req)
        else:
            User.Ensure(req)
        # link service to user account, possible merge happens behind the scenes (but doesn't effect active user)
        User.ConnectService(req.user, serviceRecord)
        return True
    return False
예제 #3
0
def auth_do(req, service):
    svc = Service.FromID(service)
    from tapiriik.services.api import APIException
    try:
        if svc.RequiresExtendedAuthorizationDetails:
            uid, authData, extendedAuthData = svc.Authorize(
                req.POST["username"], req.POST["password"])
        else:
            uid, authData = svc.Authorize(req.POST["username"],
                                          req.POST["password"])
    except APIException as e:
        if e.UserException is not None:
            return {
                "type": e.UserException.Type,
                "extra": e.UserException.Extra
            }
        return False
    if authData is not None:
        serviceRecord = Service.EnsureServiceRecordWithAuth(
            svc,
            uid,
            authData,
            extendedAuthDetails=extendedAuthData
            if svc.RequiresExtendedAuthorizationDetails else None,
            persistExtendedAuthDetails=bool(req.POST.get("persist", None)))
        # auth by this service connection
        existingUser = User.AuthByService(serviceRecord)
        # only log us in as this different user in the case that we don't already have an account
        if existingUser is not None and req.user is None:
            User.Login(existingUser, req)
        else:
            User.Ensure(req)
        # link service to user account, possible merge happens behind the scenes (but doesn't effect active user)
        User.ConnectService(req.user, serviceRecord)

        # TODO do other way. May be possible to achieve during LocalService auth?
        # restrict sync to primary server to ensure data is accessible by the web server
        # in case we are connecting local exporter
        if PRIMARY_HOST_NAME:
            db.users.update({"ConnectedServices.Service": service}, {
                "$set": {
                    "SynchronizationHostRestriction": PRIMARY_HOST_NAME
                }
            })

        return True
    return False