
Authorization and Authentication :
Authorization means "What you want to do", it tells us what privileges we have access to, that access can be anything like making changes in a database, changing the code of a repository on GitHub, or making a decision in a company.
Eg: In school, a class monitor has more privileges than a regular student, so a class monitor has more access to things like he/she can go to the staff room or can go out of the class for lunch and so on.
Authentication on the other hand means "Who you are", authentication means asking for identity. Many companies have authentication that they use so that no outsider can access their company's curatorial information.
Eg: When you go to a college, the guard at the gate asks for your Id card, you show your Id card and then only he allows you to enter the premises.
There are different ways to authenticate ourselves and the simplest one is :
HTTP Basic Authentication
import requests
from requests.auth import HTTPBasicAuth # this is used to get the basic authentication from a website
# lets take the github user example
# https://github.com/user
a = requests.get('https://github.com/user', auth = ('username','password')
With the help of from requests.auth import HTTPBasicAuth we can request from a site and using our username and password, we can post requests.
Making a repository using the Authentication method
In making a repository we will be using the "POST" method that will help us to create the repository in Github.
The Parameters we will be using are :
name: Name of the Repository
description: Description of the Repository
auto_init: Boolean value (True or False), it will create an initial commit
Json.dump : is a function that is used to convert python string to json
import requests
from requests.auth import HTTPBasicAuth
import json
a = requests.get('https://github.com/user', auth = ('username','password')
info = {'name':'name of the repo','description':'Description of repo','auto_init':'true'}
#here the info is in dictornary and we need to make it to json for the post method so we can use json.dump method
a = request.post('https://github.com/user/repo',auth = ('username','password'), data=json.dumps(info))
A repository will be created with the name that you have given with a description in your GitHub profile.
If you like this blog please leave a comment and a like 👍, thank you for your time.
Comments
Join the discussionNo comments yet. Be the first to comment.

