A easy python code how to generate a oAuthentifcation application with Github & Python
Flask GitHub Login
This is a Flask web application that allows users to log in with their GitHub account and view their GitHub projects. It utilizes OAuth authentication with GitHub and retrieves the user's projects using the GitHub API.
Images
Features
User Authentication
The application uses the GitHub OAuth flow to authenticate users. Here's how the authentication process works:
When the user accesses the application, they are redirected to the GitHub login page.
After the user logs in with their GitHub account, they are redirected back to the application with an authorization code.
The application exchanges the authorization code for an access token by making a request to GitHub's access token endpoint.
The access token is saved in the user's session for future API requests.
Project Listing
Once the user is authenticated, they can view a list of their GitHub projects. The project listing feature works as follows:
import requests
from flask import Flask, redirect, request, session, url_for
from authlib.integrations.flask_client import OAuth # Import the OAuth class
app = Flask(__name__)
app.secret_key = "some_random_string" # Replace the secret key
oauth = OAuth(app)
github = oauth.register(
name="github",
client_id="CLIENT_ID",
client_secret="CLIENT_ID_SECRET",
access_token_url="https://github.com/login/oauth/access_token",
access_token_params=None,
authorize_url="https://github.com/login/oauth/authorize",
authorize_params=None,
api_base_url="https://api.github.com/",
client_kwargs={"scope": "user:email"},
)
@app.route("/")
def index():
# Check if the username is stored in the session
username = session.get("username")
if username:
# Username is stored, display it
return f"Hello {username}! you're now logged in."
else:
# Username is not stored, redirect to the login page
return redirect(url_for("login"))
@app.route("/login")
def login():
# Check if the user is already authenticated
if "access_token" in session:
# User is already authenticated, redirect to the index page
return redirect(url_for("index"))
# User is not authenticated, start the OAuth process
return github.authorize_redirect(url_for("callback", _external=True))
@app.route("/callback")
def callback():
# Check if the user is already authenticated
if "access_token" in session:
# User is already authenticated, redirect to the index page
return redirect(url_for("index"))
# Get the OAuth code from the request
code = request.args.get("code")
# Exchange the OAuth code for an access token
access_token = get_access_token(code)
# Store the access token in the session
session["access_token"] = access_token
# Get the username from the GitHub API
username = get_username()
# Store the username in the session
session["username"] = username
# Redirect the user to the index page
return redirect(url_for("index"))
def get_access_token(code):
# Configure the access token request
payload = {
"client_id": "CLIENT_ID",
"client_secret": "CLIENT_SECRET",
"code": code,
}
headers = {
"Accept": "application/json",
}
# Send the access token request
response = requests.post(
"https://github.com/login/oauth/access_token", json=payload, headers=headers
)
# Extract the access token from the response
if response.status_code == 200:
access_token = response.json()["access_token"]
return access_token
# In case of an error, return None
return None
def get_username():
access_token = session.get("access_token")
if access_token:
headers = {
"Authorization": f"Bearer {access_token}",
"Accept": "application/vnd.github.v3+json",
}
response = requests.get("https://api.github.com/user", headers=headers)
if response.status_code == 200:
username = response.json()["login"]
return username
return None
if __name__ == "__main__":
app.run(debug=True)
A text editor programmed with Python and PyQt5 with integration to Microsoft Word and Upload-System to Github.
Text-Editor
A text editor programmed with Python and PyQt5 with integration to Microsoft Word. Read WIKI for full instruction turorial + features
🛫Get started
This repository contains the code for a simple text editor implemented in Python. The text editor allows users to open, save, and export files, as well as apply formatting such as bold, italic, and underline. This post provides instructions on how to test the text editor
To test the text editor, follow these steps:
⌨️ Install the dependencies
Navigate to the cloned repository and install the required dependencies by running the following command: pip install -r requirements.txt
🎉 Run the text editor
Execute the main Python script to launch the text editor application: python text_editor.py