- funny explaination, easy to understand INTRODUCTION TO OAUTH (IN PLAIN ENGLISH) by Rob Sobers
- more detail, contain photo explaination An Introduction to OAuth 2 by Mitchell Anicas
- interesting question, actually the question explains a lot, some security issues on-a-high-level-how-does-oauth-2-work
- boring answer How-does-OAuth-2-0-work in quora
Last active
March 30, 2018 17:20
-
-
Save githubutilities/157026e1aee66bcfd87f to your computer and use it in GitHub Desktop.
OAuth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/local/bin/python | |
| def create_github_repo(name, token): | |
| import requests | |
| import json | |
| from urlparse import urljoin | |
| GITHUB_API = 'https://api.github.com' | |
| url = urljoin(GITHUB_API, 'user/repos') | |
| payload = {} | |
| header = { | |
| 'content-type' : 'application/json', | |
| 'Authorization': 'token ' + token | |
| } | |
| payload["name"] = name | |
| # | |
| # making request | |
| # | |
| res = requests.post( | |
| url, | |
| data = json.dumps(payload), | |
| headers = header | |
| ) | |
| # if status_code is 201 return True | |
| return res.status_code == 201 | |
| if __name__ == '__main__': | |
| name = "" | |
| token = "" | |
| print create_github_repo(name=name, token=token) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/local/bin/python | |
| # get personal access token | |
| # by default it return '' | |
| def get_github_personal_access_token(username, password, note, scope=["public_repo"]): | |
| GITHUB_API = 'https://api.github.com' | |
| import requests | |
| import json | |
| from urlparse import urljoin | |
| # This API can only be accessed with username and password Basic Auth | |
| url = urljoin(GITHUB_API, 'authorizations') | |
| payload = {} | |
| payload['note'] = note | |
| payload['scopes'] = scope | |
| header = { | |
| 'content-type': 'application/json' | |
| } | |
| # | |
| # Make request | |
| # | |
| res = requests.post( | |
| url, | |
| auth = (username, password), | |
| data = json.dumps(payload), | |
| headers = header, | |
| ) | |
| j = json.loads(res.text) | |
| ret = j.get('token', '') | |
| return ret | |
| if __name__ == '__main__': | |
| import getpass | |
| username = raw_input('Github username: ') | |
| password = getpass.getpass('Github password: ') | |
| note = raw_input('Note about the personal access token') | |
| print get_github_personal_access_token(password=password, username=username, note=note) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment