示例#1
0
def yellowantRedirectUrl(request):

    code = request.GET.get("code", False)
    if code is False:
        return HttpResponse("Invalid Response")
    else:
        y = YellowAnt(app_key=settings.YELLOWANT_CLIENT_ID,
                      app_secret=settings.YELLOWANT_CLIENT_SECRET,
                      access_token=None,
                      redirect_uri=settings.YELLOWANT_REDIRECT_URL)
        access_token_dict = y.get_access_token(code)
        access_token = access_token_dict['access_token']

        yellowant_user = YellowAnt(access_token=access_token)
        user_integration = yellowant_user.create_user_integration()
        profile = yellowant_user.get_user_profile()

        print(request.user)

        global screen_name
        ut = UserToken.objects.create(
            screen_name=screen_name,
            yellowant_token=access_token,
            yellowant_id=profile['id'],
            yellowant_integration_id=user_integration['user_application'])

        return HttpResponse("User is authenticated!!!")
示例#2
0
def yellowantredirecturl(request):
    # The code is extracted from request URL and it is used to get access token json.
    # The YA_REDIRECT_URL point to this function only
    code = request.GET.get('code')
    state = request.GET.get("state")
    yellowant_redirect_state = YellowAntRedirectState.objects.get(state=state)
    user = yellowant_redirect_state.user
    print(settings.YA_REDIRECT_URL)

    y = YellowAnt(app_key=settings.YA_CLIENT_ID,
                  app_secret=settings.YA_CLIENT_SECRET,
                  access_token=None,
                  redirect_uri=settings.YA_REDIRECT_URL)
    access_token_dict = y.get_access_token(code)

    print(access_token_dict)
    access_token = access_token_dict['access_token']
    yellowant_user = YellowAnt(access_token=access_token)
    profile = yellowant_user.get_user_profile()
    user_integration = yellowant_user.create_user_integration()
    ut = YellowUserToken.objects.create(
        user=user,
        yellowant_token=access_token,
        yellowant_id=profile['id'],
        yellowant_integration_invoke_name=user_integration["user_invoke_name"],
        yellowant_integration_id=user_integration['user_application'])

    return HttpResponseRedirect(settings.SITE_PROTOCOL +
                                f"{yellowant_redirect_state.subdomain}." +
                                settings.SITE_DOMAIN_URL + settings.BASE_HREF +
                                f"integrate_app?id={ut.id}")
示例#3
0
def yellowantRedirectUrl(request):
    code = request.GET.get("code", False)
    # code = "64HDykUcK2SQPJd0VLansK9tLHvEvJ"
    if code is False:
        return HttpResponse("Invalid Response")
    else:
        y = YellowAnt(app_key=settings.YELLOWANT_CLIENT_ID,
                      app_secret=settings.YELLOWANT_CLIENT_SECRET,
                      access_token=None,
                      redirect_uri=settings.YELLOWANT_REDIRECT_URL)
        print(y)
        access_token_dict = y.get_access_token(code)
        print(access_token_dict)
        access_token = access_token_dict['access_token']
        print(access_token)

        user_yellowant_object = YellowAnt(access_token=access_token)
        profile = user_yellowant_object.get_user_profile()
        yellowant_user = YellowAnt(access_token=access_token)
        user_integration = yellowant_user.create_user_integration()
        # print(user)
        print(user_integration)

        ut = UserToken.objects.create(
            yellowant_token=access_token,
            yellowant_id=profile['id'],
            yellowant_integration_id=user_integration['user_application'])
        return HttpResponse("User Authenticated")
示例#4
0
def yellowant_oauth_redirect(request):
    """Receive the oauth2 code from YA to generate a new user integration
    This method calls utilizes the YA Python SDK to create a new user integration on YA.
    This method only provides the code for creating a new user integration on YA.
    Beyond that, you might need to authenticate the user on the actual application
    (whose APIs this application will be calling) and store a relation
    between these user auth details and the YA user integration.
    """
    # oauth2 code from YA, passed as GET params in the url
    code = request.GET.get("code")

    # the unique string to identify the user for which we will create an integration
    state = request.GET.get("state")

    # fetch user with the help of state
    yellowant_redirect_state = YellowAntRedirectState.objects.get(state=state)
    user = yellowant_redirect_state.user

    # initialize the YA SDK client with your application credentials
    ya_client = YellowAnt(app_key=settings.YA_CLIENT_ID,
                          app_secret=settings.YA_CLIENT_SECRET,
                          access_token=None,
                          redirect_uri=settings.YA_REDIRECT_URL)

    # get the access token for a user integration from YA against the code
    access_token_dict = ya_client.get_access_token(code)
    access_token = access_token_dict["access_token"]

    # reinitialize the YA SDK client with the user integration access token
    ya_client = YellowAnt(access_token=access_token)

    # get YA user details
    ya_user = ya_client.get_user_profile()

    # create a new user integration for your application
    user_integration = ya_client.create_user_integration()

    # save the YA user integration details in your database
    ut = UserIntegration.objects.create(
        user=user,
        yellowant_user_id=ya_user["id"],
        yellowant_team_subdomain=ya_user["team"]["domain_name"],
        yellowant_integration_id=user_integration["user_application"],
        yellowant_integration_invoke_name=user_integration["user_invoke_name"],
        yellowant_integration_token=access_token)

    aws.objects.create(id=ut, AWS_APIAccessKey="", AWS_APISecretAccess="")
    # A new YA user integration has been created and the details have been successfully
    # saved in your application's database. However, we have only created an integration on YA.
    # As a developer, you need to begin an authentication process for the actual application,
    # whose API this application is connecting to. Once, the authentication process
    # for the actual application is completed with the user, you need to create a db
    # entry which relates the YA user integration, we just created, with the actual application
    # authentication details of the user. This application will then be able to identify
    #  the actual application accounts corresponding to each YA user integration.

    # return HttpResponseRedirect("to the actual application authentication URL")

    # return HttpResponseRedirect(reverse("accounts/"), kwargs={"id":ut})
    return HttpResponseRedirect("/")
示例#5
0
def redirect_url(request):
    #YellowAnt redirects to this view with code and state values
    code = request.GET.get("code", False)
    #state = request.GET.get("state", False)

    #Exchange code with permanent token
    y = YellowAnt(app_key=settings.YA_CLIENT_ID,
                  app_secret=settings.YA_CLIENT_SECRET,
                  access_token=None,
                  redirect_uri=settings.YELLOWANT_REDIRECT_URL)
    access_token_dict = y.get_access_token(code)
    access_token = access_token_dict['access_token']

    #List of emails of users allowed access to this application
    users_allowed_emails = [
        '*****@*****.**', '*****@*****.**', '*****@*****.**',
        '*****@*****.**'
    ]

    #Using token to fetch user details
    x = YellowAnt(access_token=access_token)
    profile = x.get_user_profile()

    if profile['email'] in users_allowed_emails:
        q = x.create_user_integration()
        user_application = q['user_application']
        ti = AdminUsers.objects.create(
            yellowant_user_id=profile['id'],
            yellowant_integration_id=user_application,
            yellowant_integration_user_invoke_name=q['user_invoke_name'],
            yellowant_user_token=access_token)
        return HttpResponse("You are now authenticated!")
    else:
        return HttpResponse("You are not allowed to access this application!")
示例#6
0
def yellowantRedirecturl(request):
    print("In yellowantRedirecturl")
    ''' Receive the oauth2 code from YA to generate a new user integration
        This method calls utilizes the YA Python SDK to create a new user integration on YA.
        This method only provides the code for creating a new user integration on YA.
        Beyond that, you might need to authenticate the user on
        the actual application (whose APIs this application will be calling) and store a relation
        between these user auth details and the YA user integration.
    '''

    # Oauth2 code from YA, passed as GET params in the url
    code = request.GET.get('code')

    # The unique string to identify the user for which we will create an integration
    state = request.GET.get("state")

    # Fetch user with help of state from database
    yellowant_redirect_state = YellowAntRedirectState.objects.get(state=state)
    user = yellowant_redirect_state.user

    # Initialize the YA SDK client with your application credentials
    y = YellowAnt(app_key=settings.YELLOWANT_CLIENT_ID,
                  app_secret=settings.YELLOWANT_CLIENT_SECRET,
                  access_token=None,
                  redirect_uri=settings.YELLOWANT_REDIRECT_URL)

    # Getting the acccess token
    access_token_dict = y.get_access_token(code)
    print(access_token_dict)

    access_token = access_token_dict['access_token']

    # Getting YA user details
    yellowant_user = YellowAnt(access_token=access_token)
    profile = yellowant_user.get_user_profile()

    # Creating a new user integration for the application
    user_integration = yellowant_user.create_user_integration()
    hash_str = str(uuid.uuid4()).replace("-", "")[:25]
    ut = YellowUserToken.objects.create(user=user, yellowant_token=access_token,
                                        yellowant_id=profile['id'],
                                        yellowant_integration_invoke_name=user_integration\
                                            ["user_invoke_name"],
                                        yellowant_integration_id=user_integration\
                                            ['user_application'],
                                        webhook_id=hash_str)

    state = str(uuid.uuid4())
    AppRedirectState.objects.create(user_integration=ut, state=state)

    url = "https://www.dropbox.com/oauth2/authorize/"
    params = {
        'response_type': 'code',
        'client_id': settings.DROPBOX_CLIENT_ID,
        'redirect_uri': settings.DROPBOX_REDIRECT_URL,
        'state': state
    }
    url += '?' + urllib.parse.urlencode(params)
    return HttpResponseRedirect(url)
示例#7
0
def yellowant_redirecturl(request):
    """Receive the oauth2 code from YA to generate a new user integration

    This method calls utilizes the YA Python SDK to create a new user
    integration on YA.
    This method only provides the code for creating a new user integration on YA.
    Beyond that, you might need to
    authenticate the user on the actual application (whose APIs this application
    will be calling) and store a relation
    between these user auth details and the YA user integration.
    """
    print("In yellowant_redirecturl")
    code = request.GET.get('code')
    state = request.GET.get("state")
    yellowant_redirect_state = YellowAntRedirectState.objects.get(state=state)
    print(code)
    print(yellowant_redirect_state)
    user = yellowant_redirect_state.user
    print(settings.YELLOWANT_REDIRECT_URL)

    # initialize the YA SDK client with your application credentials
    print(user)
    ya_client = YellowAnt(app_key=settings.YELLOWANT_CLIENT_ID,
                          app_secret=settings.YELLOWANT_CLIENT_SECRET,
                          access_token=None,
                          redirect_uri=settings.YELLOWANT_REDIRECT_URL)

    access_token_dict = ya_client.get_access_token(code)
    print(access_token_dict)
    access_token = access_token_dict['access_token']
    yellowant_user = YellowAnt(access_token=access_token)
    profile = yellowant_user.get_user_profile()
    user_integration = yellowant_user.create_user_integration()
    hash_str = str(uuid.uuid4()).replace("-", "")[:25]

    # save the YA user integration details in your database
    ut = YellowUserToken.objects.create(
        user=user,
        yellowant_token=access_token,
        yellowant_id=profile['id'],
        yellowant_integration_invoke_name=user_integration["user_invoke_name"],
        yellowant_integration_id=user_integration['user_application'],
        webhook_id=hash_str)

    """A new YA user integration has been created and the details have been successfully saved in
    your application's database. However, we have only created an integration on YA.
    As a developer, you need to begin an authentication process for the actual application,
    whose API this application is connecting to. Once, the authentication process for the actual
    application is completed with the user, you need to create a db entry which relates the YA user
    integration, we just created, with the actual application authentication details of the user.
    This application will then be able to identify the actual application accounts corresponding\
    to each YA user integration.""" #pylint: disable=pointless-string-statement

    print("exiting yellowant_redirecturl")
    return HttpResponseRedirect(settings.SITE_PROTOCOL +
                                f"{yellowant_redirect_state.subdomain}." +
                                settings.SITE_DOMAIN_URL + settings.BASE_HREF +
                                f"integrate_app?id={ut.id}")
示例#8
0
文件: views.py 项目: vimalvk9/dropbox
def yellowantRedirecturl(request):
    print("In yellowantRedirecturl")

    ''' Receive the oauth2 code from YA to generate a new user integration
        This method calls utilizes the YA Python SDK to create a new user integration on YA.
        This method only provides the code for creating a new user integration on YA.
        Beyond that, you might need to authenticate the user on
        the actual application (whose APIs this application will be calling) and store a relation
        between these user auth details and the YA user integration.
    '''

    # Oauth2 code from YA, passed as GET params in the url
    code = request.GET.get('code')

    # The unique string to identify the user for which we will create an integration
    state = request.GET.get("state")

    # Fetch user with help of state from database
    yellowant_redirect_state = YellowAntRedirectState.objects.get(state=state)
    user = yellowant_redirect_state.user

    # Initialize the YA SDK client with your application credentials
    y = YellowAnt(app_key=settings.YELLOWANT_CLIENT_ID,
                  app_secret=settings.YELLOWANT_CLIENT_SECRET,
                  access_token=None, redirect_uri=settings.YELLOWANT_REDIRECT_URL)

    # Getting the acccess token
    access_token_dict = y.get_access_token(code)
    print(access_token_dict)

    access_token = access_token_dict['access_token']



    # Getting YA user details
    yellowant_user = YellowAnt(access_token=access_token)
    profile = yellowant_user.get_user_profile()

    # Creating a new user integration for the application
    user_integration = yellowant_user.create_user_integration()
    hash_str = str(uuid.uuid4()).replace("-", "")[:25]
    ut = YellowUserToken.objects.create(user=user, yellowant_token=access_token,
                                        yellowant_id=profile['id'],
                                        yellowant_integration_invoke_name=user_integration\
                                            ["user_invoke_name"],
                                        yellowant_integration_id=user_integration\
                                            ['user_application'],
                                        webhook_id=hash_str)

    state = str(uuid.uuid4())
    AppRedirectState.objects.create(user_integration=ut, state=state)

    url = "https://www.dropbox.com/oauth2/authorize/"
    params = { 'response_type': 'code','client_id': settings.DROPBOX_CLIENT_ID,
               'redirect_uri': settings.DROPBOX_REDIRECT_URL,
               'state': state}
    url += '?' + urllib.parse.urlencode(params)
    return HttpResponseRedirect(url)
示例#9
0
def yellowantRedirecturl(request):

    ''' Receive the oauth2 code from YA to generate a new user integration
        This method calls utilizes the YA Python SDK to create a new user integration on YA.
        This method only provides the code for creating a new user integration on YA.
        Beyond that, you might need to authenticate the user on
        the actual application (whose APIs this application will be calling) and store a relation
        between these user auth details and the YA user integration.
    '''

    # Oauth2 code from YA, passed as GET params in the url
    code = request.GET.get('code')

    # The unique string to identify the user for which we will create an integration
    state = request.GET.get("state")

    # Fetch user with help of state from database
    yellowant_redirect_state = YellowAntRedirectState.objects.get(state=state)
    user = yellowant_redirect_state.user

    # Initialize the YA SDK client with your application credentials
    y = YellowAnt(app_key=settings.YELLOWANT_CLIENT_ID,
                  app_secret=settings.YELLOWANT_CLIENT_SECRET,
                  access_token=None, redirect_uri=settings.YELLOWANT_REDIRECT_URL)
    print(settings.YELLOWANT_REDIRECT_URL)
    # Getting the acccess token
    access_token_dict = y.get_access_token(code)
    access_token = access_token_dict['access_token']

    # Getting YA user details
    yellowant_user = YellowAnt(access_token=access_token)
    profile = yellowant_user.get_user_profile()

    # Creating a new user integration for the application
    user_integration = yellowant_user.create_user_integration()
    hash_str = str(uuid.uuid4()).replace("-", "")[:25]
    ut = YellowUserToken.objects.create(user=user, yellowant_token=access_token,
                                        yellowant_id=profile['id'],
                                        yellowant_integration_invoke_name=user_integration\
                                            ["user_invoke_name"],
                                        yellowant_integration_id=user_integration\
                                            ['user_application'],
                                        webhook_id=hash_str)
    state = str(uuid.uuid4())
    AppRedirectState.objects.create(user_integration=ut, state=state)
    sp_token = ""                 # "11649b9b-ea84-47fa-aecb-9faf3ab447bd"
    page_id = ""
    sut = StatuspageUserToken.objects.create(user_integration=ut, statuspage_access_token=sp_token, webhook_id=hash_str)

    #print("------------------")
    #print(sut.user_integration_id)

    ''' No need to create a page detail object here '''
    #page_detail_object = PageDetail.objects.create(user_integration_id=sut.user_integration_id, page_id=page_id)
    #print(page_detail_object)
    # Redirecting to home page
    return HttpResponseRedirect("/")
示例#10
0
文件: views.py 项目: vimalvk9/mailgun
def yellowantRedirecturl(request):
    ''' Receive the oauth2 code from YA to generate a new user integration
        This method calls utilizes the YA Python SDK to create a new user integration on YA.
        This method only provides the code for creating a new user integration on YA.
        Beyond that, you might need to authenticate the user on
        the actual application (whose APIs this application will be calling) and store a relation
        between these user auth details and the YA user integration.
    '''

    # Oauth2 code from YA, passed as GET params in the url
    code = request.GET.get('code')

    # The unique string to identify the user for which we will create an integration
    state = request.GET.get("state")

    # Fetch user with help of state from database
    yellowant_redirect_state = YellowAntRedirectState.objects.get(state=state)
    user = yellowant_redirect_state.user

    # Initialize the YA SDK client with your application credentials
    y = YellowAnt(app_key=settings.YELLOWANT_CLIENT_ID,
                  app_secret=settings.YELLOWANT_CLIENT_SECRET,
                  access_token=None,
                  redirect_uri=settings.YELLOWANT_REDIRECT_URL)
    print(settings.YELLOWANT_REDIRECT_URL)
    # Getting the acccess token
    access_token_dict = y.get_access_token(code)
    access_token = access_token_dict['access_token']

    # Getting YA user details
    yellowant_user = YellowAnt(access_token=access_token)
    profile = yellowant_user.get_user_profile()

    # Creating a new user integration for the application
    user_integration = yellowant_user.create_user_integration()
    hash_str = str(uuid.uuid4()).replace("-", "")[:25]
    ut = YellowUserToken.objects.create(user=user, yellowant_token=access_token,
                                        yellowant_id=profile['id'],
                                        yellowant_integration_invoke_name=user_integration\
                                            ["user_invoke_name"],
                                        yellowant_integration_id=user_integration\
                                            ['user_application'],
                                        webhook_id=hash_str)

    ## Initially the mailgun object contians no access token so kept empty
    ## On submiting API key it is updated

    mail_gun_token = ""
    mail_object = MailGunUserToken.objects.create(user_integration=ut,
                                                  accessToken=mail_gun_token,
                                                  webhook_id=hash_str)

    url = settings.BASE_URL + "/webhook/" + ut.webhook_id + "/"
    print(url)

    return HttpResponseRedirect("/")
示例#11
0
def yellowant_oauth_redirect(request):
    """Receive the oauth2 code from YA to generate a new user integration"""

    code = request.GET.get("code")

    # the unique string to identify the user for which we will create an integration
    state = request.GET.get("state")

    # fetch user with the help of state
    yellowant_redirect_state = YellowAntRedirectState.objects.get(state=state)
    user = yellowant_redirect_state.user

    # initialize the YA SDK client with your application credentials
    ya_client = YellowAnt(app_key=settings.YA_CLIENT_ID,
                          app_secret=settings.YA_CLIENT_SECRET,
                          access_token=None,
                          redirect_uri=settings.YA_REDIRECT_URL)

    # get the access token for a user integration from YA against the code
    access_token_dict = ya_client.get_access_token(code)

    access_token = access_token_dict["access_token"]

    # reinitialize the YA SDK client with the user integration access token
    ya_client = YellowAnt(access_token=access_token)

    # get YA user details
    ya_user = ya_client.get_user_profile()

    # create a new user integration for your application
    user_integration = ya_client.create_user_integration()

    webhook_id = str(uuid.uuid4())
    # save the YA user integration details in your database
    user_t = UserIntegration.objects.create(
        user=user,
        yellowant_user_id=ya_user["id"],
        yellowant_team_subdomain=ya_user["team"]["domain_name"],
        yellowant_integration_id=user_integration["user_application"],
        yellowant_integration_invoke_name=user_integration["user_invoke_name"],
        yellowant_integration_token=access_token,
        webhook_id=webhook_id)

    url = settings.SITE_PROTOCOL + f'{yellowant_redirect_state.subdomain}.' + settings.SITE_DOMAIN_URL+ \
          settings.BASE_HREF
    return HttpResponseRedirect(url)
示例#12
0
def yellowantRedirecturl(request):
    """ Receive the oauth2 code from YA to generate a new user integration
            This method calls utilizes the YA Python SDK to create a new user integration on YA.
            This method only provides the code for creating a new user integration on YA.
            Beyond that, you might need to authenticate the user on
            the actual application (whose APIs this application will be calling)
            and store a relation between these user auth details and the YA user integration.
    """
    # Oauth2 code from YA, passed as GET params in the url
    code = request.GET.get('code')

    # The unique string to identify the user for which we will create an integration
    state = request.GET.get("state")

    # Fetch user with help of state from database
    yellowant_redirect_state = YellowAntRedirectState.objects.get(state=state)
    user = yellowant_redirect_state.user

    # Initialize the YA SDK client with your application credentials
    y = YellowAnt(app_key=settings.YELLOWANT_CLIENT_ID,
                  app_secret=settings.YELLOWANT_CLIENT_SECRET,
                  access_token=None,
                  redirect_uri=settings.YELLOWANT_REDIRECT_URL)

    # Getting the acccess token
    access_token_dict = y.get_access_token(code)
    access_token = access_token_dict["access_token"]

    # Getting YA user details
    yellowant_user = YellowAnt(access_token=access_token)
    profile = yellowant_user.get_user_profile()

    # Creating a new user integration for the application
    user_integration = yellowant_user.create_user_integration()
    hash_str = str(uuid.uuid4()).replace("-", "")[:25]
    ut = YellowUserToken.objects.create(user=user, yellowant_token=access_token,
                                        yellowant_id=profile['id'],
                                        yellowant_integration_invoke_name=user_integration \
                                            ["user_invoke_name"],
                                        yellowant_integration_id=user_integration \
                                            ['user_application'], webhook_id=hash_str)
    state = str(uuid.uuid4())
    AppRedirectState.objects.create(user_integration=ut, state=state)

    web_url = settings.BASE_URL + "/webhook/" + hash_str + "/"
    print(web_url)

    # Redirecting the user to the zoho oauth url to get the state and the auth code
    url = settings.ZOHO_OAUTH_URL
    params = {
        'scope': ','.join(str(i) for i in SCOPES),
        'client_id': settings.ZOHO_CLIENT_ID,
        'state': state,
        'response_type': 'code',
        'redirect_uri': settings.ZOHO_REDIRECT_URL,
        'access_type': 'offline',
        'prompt': 'Consent'
    }

    url += urllib.parse.urlencode(params)

    print(url)
    return HttpResponseRedirect(url)
示例#13
0
def yellowant_redirecturl(request):
    """Receive the oauth2 code from YA to generate a new user integration

    This method calls utilizes the YA Python SDK to create a new user
    integration on YA.
    This method only provides the code for creating a new user integration on YA.
    Beyond that, you might need to
    authenticate the user on the actual application (whose APIs this application
    will be calling) and store a relation
    between these user auth details and the YA user integration.
    """
    print("In yellowant_redirecturl")

    # oauth2 code from YA, passed as GET params in the url
    code = request.GET.get('code')

    # the unique string to identify the user for which we will create an integration
    state = request.GET.get("state")

    yellowant_redirect_state = YellowAntRedirectState.objects.get(state=state)
    user = yellowant_redirect_state.user

    # initialize the YA SDK client with your application credentials
    ya_client = YellowAnt(app_key=settings.YELLOWANT_CLIENT_ID,\
    app_secret=settings.YELLOWANT_CLIENT_SECRET, access_token=None,\
    redirect_uri=settings.YELLOWANT_REDIRECT_URL)

    # access_token_dict is json structured
    # get the access token for a user integration from YA against the code
    access_token_dict = ya_client.get_access_token(code)
    access_token = access_token_dict['access_token']

    # reinitialize the YA SDK client with the user integration access token
    yellowant_user = YellowAnt(access_token=access_token)

    # get YA user details
    profile = yellowant_user.get_user_profile()

    # create a new user integration for your application
    user_integration = yellowant_user.create_user_integration()
    hash_str = str(uuid.uuid4()).replace("-", "")[:25]

    # save the YA user integration details in your database
    u_t = YellowUserToken.objects.create(\
    user=user,\
    yellowant_token=access_token,\
    yellowant_id=profile['id'],\
    yellowant_integration_invoke_name=user_integration["user_invoke_name"],\
    yellowant_intergration_id=user_integration['user_application'],\
    webhook_id=hash_str)

    """A new YA user integration has been created and the details have been successfully saved in
    your application's database. However, we have only created an integration on YA.
    As a developer, you need to begin an authentication process for the actual application,
    whose API this application is connecting to. Once, the authentication process for the actual
    application is completed with the user, you need to create a db entry which relates the YA user
    integration, we just created, with the actual application authentication details of the user.
    This application will then be able to identify the actual application accounts corresponding\
    to each YA user integration.""" #pylint: disable=pointless-string-statement

    return HttpResponseRedirect("/integrate_app?id={}".format(str(u_t.id)))
示例#14
0
def yellowant_oauth_redirect(request):
    """Receive the oauth2 code from YA to generate a new user integration
    
    This method calls utilizes the YA Python SDK to create a new user integration on YA.
    This method only provides the code for creating a new user integration on YA. Beyond that, you might need to 
    authenticate the user on the actual application (whose APIs this application will be calling) and store a relation
    between these user auth details and the YA user integration.
    """
    # oauth2 code from YA, passed as GET params in the url
    print('inside yellowant_oauth_redirect')
    code = request.GET.get("code")
    print(code)

    print("Hello\n\n")

    # the unique string to identify the user for which we will create an integration
    state = request.GET.get("state")
    print("statis is")
    print(state)
    # fetch user with the help of state
    yellowant_redirect_state = YellowAntRedirectState.objects.get(state=state)
    user = yellowant_redirect_state.user
    print("user is")
    print(user)

    # initialize the YA SDK client with your application credentials
    ya_client = YellowAnt(app_key=settings.YA_CLIENT_ID, app_secret=settings.YA_CLIENT_SECRET, access_token=None,
        redirect_uri=settings.YA_REDIRECT_URL)


    # get the access token for a user integration from YA against the code
    print ("here")
    access_token_dict = ya_client.get_access_token(code)
    print(str(access_token_dict)+" Accesstoken")
    print("Inside \n\n")
    access_token = access_token_dict["access_token"]

    # reinitialize the YA SDK client with the user integration access token
    ya_client = YellowAnt(access_token=access_token)

    # get YA user details
    ya_user = ya_client.get_user_profile()

    # create a new user integration for your application
    user_integration = ya_client.create_user_integration()

    # save the YA user integration details in your database
    ut=UserIntegration.objects.create(user=user, yellowant_user_id=ya_user["id"],
        yellowant_team_subdomain=ya_user["team"]["domain_name"],
        yellowant_integration_id=user_integration["user_application"],
        yellowant_integration_invoke_name=user_integration["user_invoke_name"],
        yellowant_integration_token=access_token)

    Agile_Credentials.objects.create(user_integration=ut,AGILE_DOMAIN_NAME="",AGILE_EMAIL_ID="",AGILE_API_KEY="",AGILE_UPDATE_LOGIN_FLAG=False)
    
    # A new YA user integration has been created and the details have been successfully saved in your application's 
    # database. However, we have only created an integration on YA. As a developer, you need to begin an authentication 
    # process for the actual application, whose API this application is connecting to. Once, the authentication process 
    # for the actual application is completed with the user, you need to create a db entry which relates the YA user
    # integration, we just created, with the actual application authentication details of the user. This application
    # will then be able to identify the actual application accounts corresponding to each YA user integration.

    # return HttpResponseRedirect("to the actual application authentication URL")

    print(str(user_integration["user_application"])+"  integration ID")

    # agc=Agile_Credentials()
    # agc.user_integration=UserIntegration.objects.get(yellowant_integration_id=user_integration["user_application"])
    # agc.save()
    global integ_id
    integ_id= UserIntegration.objects.get(yellowant_integration_id=user_integration["user_application"])
    return HttpResponseRedirect("/")
示例#15
0
def yellowantRedirecturl(request):
    print("yellowantRedirecturl")
    ''' Receive the oauth2 code from YA to generate a new user integration
        This method calls utilizes the YA Python SDK to create a new user integration on YA.
        This method only provides the code for creating a new user integration on YA.
        Beyond that, you might need to authenticate the user on
        the actual application (whose APIs this application will be calling) and store a relation
        between these user auth details and the YA user integration.
    '''

    # Oauth2 code from YA, passed as GET params in the url
    code = request.GET.get('code')

    # The unique string to identify the user for which we will create an integration
    state = request.GET.get("state")

    # Fetch user with help of state from database
    yellowant_redirect_state = YellowAntRedirectState.objects.get(state=state)
    user = yellowant_redirect_state.user

    # Initialize the YA SDK client with your application credentials
    y = YellowAnt(app_key=settings.YELLOWANT_CLIENT_ID,
                  app_secret=settings.YELLOWANT_CLIENT_SECRET,
                  access_token=None,
                  redirect_uri=settings.YELLOWANT_REDIRECT_URL)

    # Getting the acccess token
    access_token_dict = y.get_access_token(code)
    access_token = access_token_dict['access_token']

    # Getting YA user details
    yellowant_user = YellowAnt(access_token=access_token)
    profile = yellowant_user.get_user_profile()

    # Creating a new user integration for the application
    user_integration = yellowant_user.create_user_integration()
    hash_str = str(uuid.uuid4()).replace("-", "")[:25]
    ut = YellowUserToken.objects.create(user=user, yellowant_token=access_token,
                                        yellowant_id=profile['id'],
                                        yellowant_integration_invoke_name=user_integration\
                                            ["user_invoke_name"],
                                        yellowant_integration_id=user_integration\
                                            ['user_application'],
                                        webhook_id=hash_str)

    # state = get_CSRF_token(request)
    # AppRedirectState.objects.create(user_integration=ut, state=state)
    #
    # qut = QuickbookUserToken.objects.create(user_integration=ut, accessToken=" ",
    #                                         refreshExpiry=0, tokenType=" ",
    #                                         refreshToken=" ",
    #                                         accessTokenExpiry=0,
    #                                         )
    # return HttpResponseRedirect("/")

    state = str(uuid.uuid4())  #get_CSRF_token(request)
    AppRedirectState.objects.create(user_integration=ut, state=state)
    # user = User.objects.get(id=request.user.id)
    # YellowAntRedirectState.objects.create(user=user,state=state)

    url = "https://appcenter.intuit.com/connect/oauth2"  #getDiscoveryDocument.auth_endpoint
    params = {
        'scope': settings.ACCOUNTING_SCOPE,
        'redirect_uri': settings.QUICKBOOKS_REDIRECT_URL,
        'response_type': 'code',
        'state': state,
        'client_id': settings.QUICKBOOKS_CLIENT_ID
    }
    url += '?' + urllib.parse.urlencode(params)
    return HttpResponseRedirect(url)
示例#16
0
def yellowant_oauth_redirect(request):
    """Receive the oauth2 code from YA to generate a new user integration
    
    This method calls utilizes the YA Python SDK to create a new user integration on YA.
    This method only provides the code for creating a new user integration on YA. Beyond that, you might need to 
    authenticate the user on the actual application (whose APIs this application will be calling) and store a relation
    between these user auth details and the YA user integration.
    """
    # oauth2 code from YA, passed as GET params in the url
    print('inside yellowant_oauth_redirect')
    code = request.GET.get("code")
    print(code)

    print("Hello\n\n")

    # the unique string to identify the user for which we will create an integration
    state = request.GET.get("state")
    print("statis is")
    print(state)
    # fetch user with the help of state
    yellowant_redirect_state = YellowAntRedirectState.objects.get(state=state)
    user = yellowant_redirect_state.user
    print("user is")
    print(user)

    # initialize the YA SDK client with your application credentials
    ya_client = YellowAnt(app_key=settings.YA_CLIENT_ID, app_secret=settings.YA_CLIENT_SECRET, access_token=None,
        redirect_uri=settings.YA_REDIRECT_URL)


    # get the access token for a user integration from YA against the code
    print ("here")
    access_token_dict = ya_client.get_access_token(code)
    print(str(access_token_dict)+" Accesstoken")
    print("Inside \n\n")
    access_token = access_token_dict["access_token"]

    # reinitialize the YA SDK client with the user integration access token
    ya_client = YellowAnt(access_token=access_token)

    # get YA user details
    ya_user = ya_client.get_user_profile()

    # create a new user integration for your application
    user_integration = ya_client.create_user_integration()

    # save the YA user integration details in your database
    ut=UserIntegration.objects.create(user=user, yellowant_user_id=ya_user["id"],
        yellowant_team_subdomain=ya_user["team"]["domain_name"],
        yellowant_integration_id=user_integration["user_application"],
        yellowant_integration_invoke_name=user_integration["user_invoke_name"],
        yellowant_integration_token=access_token)

    Xero_Credentials.objects.create(user_integration=ut,XERO_OAUTH_SECRET='0',XERO_OAUTH_TOKEN='0',XERO_EXPIRE='0',XERO_AUTH_EXPIRE='0' ,XERO_UPDATE_LOGIN_FLAG=False)
    
    # A new YA user integration has been created and the details have been successfully saved in your application's 
    # database. However, we have only created an integration on YA. As a developer, you need to begin an authentication 
    # process for the actual application, whose API this application is connecting to. Once, the authentication process 
    # for the actual application is completed with the user, you need to create a db entry which relates the YA user
    # integration, we just created, with the actual application authentication details of the user. This application
    # will then be able to identify the actual application accounts corresponding to each YA user integration.
    # return HttpResponseRedirect("to the actual application authentication URL")

    print(str(user_integration["user_application"])+"  integration ID")


    global integ_id
    global saved_state
    global token
    integ_id= UserIntegration.objects.get(yellowant_integration_id=user_integration["user_application"])


    #-------------------------------------------------------------------------------------------------
    credentials=PublicCredentials('BGJJ6JSSEAGIRWQ9SYKA1T3O7Y6IPF','2JRHWN0QQ1K0AHVDZVUPKCVIQKUUNB','http://127.0.0.1:8000/return/')
    print(credentials.url)
    webbrowser.open(credentials.url)
    time.sleep(15)
    #time.sleep(60) for the user
    credentials.verify(token)
    xero=Xero(credentials)
    saved_state=credentials.state
    print(str(saved_state)+"saved_state")
    s1=saved_state['oauth_expires_at']
    s2=saved_state['oauth_authorization_expires_at']
    print("\n\n")
    print(s1)
    print(s2)
    s1=s1.strftime('%Y%m%d%H%M%S%f')
    s2=s2.strftime('%Y%m%d%H%M%S%f')
    #new_date=datetime.datetime.strptime(s1,'%Y%m%d%H%M%S%f')
    #print(new_date)
    t1=saved_state['oauth_token']
    t2=saved_state['oauth_token_secret']
    obj=Xero_Credentials.objects.get(user_integration_id=integ_id.id)
    obj.XERO_OAUTH_TOKEN=t1
    obj.XERO_OAUTH_SECRET=t2
    obj.XERO_EXPIRE=s1
    obj.XERO_AUTH_EXPIRE=s2
    obj.XERO_UPDATE_LOGIN_FLAG=True
    print(str(obj.XERO_AUTH_EXPIRE)+"  helloooo")
    obj.save()

    new_credentials=PublicCredentials(**saved_state)
    xero=Xero(new_credentials)
    print("successful authentication")


    return HttpResponseRedirect("/")