Exemplo n.º 1
0
def callback(request):
    # callback happens from the redirect_uri you've provided
    # we're handed the code and state from BACK from the api server
    state = request.GET.get("state")
    code = request.GET.get("code")
    # build the client
    client = FindingsAPIClient(API_KEY, API_SECRET)
    # ask the provider for the final access_token
    response = client.get_access_token(code, state)
    if response.get("access_token"):
        # save the token locally
        access_token, created = AccessToken.objects.get_or_create(
            access_token=response.get("access_token"),
            expires_in=response.get("expires_in"),
            refresh_token=response.get("refresh_token"),
            )
        # we're done, go home
        return redirect("/apiclient/")
    return HttpResponse()