@login_required
def callback(request):
    """
    Step 2 of OAuth: fetch the token.
    """
    try:
        oauth_state = request.session['oauth_state']
    except __HOLE__:
        return HttpResponseBadRequest('Missing oauth state.')

    github = OAuth2Session(settings.GITHUB_CLIENT_ID, state=oauth_state)
    token = github.fetch_token(
        settings.GITHUB_TOKEN_URL,
        client_secret=settings.GITHUB_CLIENT_SECRET,
        authorization_response=request.build_absolute_uri()
    )

    try:
        OAuthToken.objects.create(user=request.user, value=token['access_token'])
    except (KeyError, TypeError):
        return HttpResponseBadRequest('Cannot read access_token.')

    Repository.add_user_to_known_repositories(request.user)
    return redirect("home")
dataset/ETHPy150Open m-vdb/github-buildservice-boilerplate/buildservice/views/oauth.py/callback