0

I am making this app using python, Flask_OAuthlib, and heroku to get access to the public repo of user's Github and create a repo and copy the required files over there. The app gets connected and also receives the following permissions as an Authorized OAuth app. Github permissions to my OAuth app

Then I have this piece of code to create a repository in public repos space of user's Github and copy some files there

177   @app.route('/replicate', methods=['GET', 'POST'])
178   def replicate():
179  
170       g = Github(theToken)
181       repo_name = request.form['repo']
182       user = g.get_user()
183       repo = user.create_repo(repo_name)  

This code is triggered when the user pushes a button and that button is only accessible only when logged in, and the app shows the user name and profile pictures from its Github. Therefore it is very well in the session with Github. But then heroku makes this error:

github.GithubException.GithubException: 401 {'message': 'Requires authentication'

I can see that there is a problem with authentication. theToken is captured this way. First I have created a theToken=None at the top of my code, then in the /login part I capture it as below:

78   @github.tokengetter
79   def get_github_oauth_token():
80       theToken = session.get('github_token')
81       return session.get('github_token')

I wonder what I am missing here. Thanks for your help

BobbyF
  • 431
  • 1
  • 7
  • 19

1 Answers1

0

I could figure out the problem. For some reason defining a global variable for getting theToken and using it later did not work. I simply moved line 80 to line 179 and it's working very well now! oh, and with a small correction as: theToken = session.get('github_token')[0], because the get function returns a tuple of length 2 for which the first value is the access token and the second one is the secret key.

Hope this question and answer can be a kind of help for someone in the future!

BobbyF
  • 431
  • 1
  • 7
  • 19