-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from YaleComputerSociety/basic-firebase-integr…
…ation add basic CAS login api integration
- Loading branch information
Showing
6 changed files
with
154 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,66 @@ | ||
<!doctype html> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>This is the title of the webpage!</title> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Welcome to Firebase Hosting</title> | ||
|
||
<!-- update the version number as needed --> | ||
<script defer src="/__/firebase/10.5.0/firebase-app-compat.js"></script> | ||
<!-- include only the Firebase features as you need --> | ||
<script defer src="/__/firebase/10.5.0/firebase-auth-compat.js"></script> | ||
<script defer src="/__/firebase/10.5.0/firebase-database-compat.js"></script> | ||
<script defer src="/__/firebase/10.5.0/firebase-firestore-compat.js"></script> | ||
<script defer src="/__/firebase/10.5.0/firebase-functions-compat.js"></script> | ||
<script defer src="/__/firebase/10.5.0/firebase-messaging-compat.js"></script> | ||
<script defer src="/__/firebase/10.5.0/firebase-storage-compat.js"></script> | ||
<script defer src="/__/firebase/10.5.0/firebase-analytics-compat.js"></script> | ||
<script defer src="/__/firebase/10.5.0/firebase-remote-config-compat.js"></script> | ||
<script defer src="/__/firebase/10.5.0/firebase-performance-compat.js"></script> | ||
|
||
<!-- | ||
initialize the SDK after all desired features are loaded, set useEmulator to false | ||
to avoid connecting the SDK to running emulators. | ||
--> | ||
<script defer src="/__/firebase/init.js?useEmulator=true"></script> | ||
|
||
<style media="screen"> | ||
body { background: #ECEFF1; color: rgba(0,0,0,0.87); font-family: Roboto, Helvetica, Arial, sans-serif; margin: 0; padding: 0; } | ||
#message { background: white; max-width: 360px; margin: 100px auto 16px; padding: 32px 24px; border-radius: 3px; } | ||
#message h2 { color: #ffa100; font-weight: bold; font-size: 16px; margin: 0 0 8px; } | ||
#message h1 { font-size: 22px; font-weight: 300; color: rgba(0,0,0,0.6); margin: 0 0 16px;} | ||
#message p { line-height: 140%; margin: 16px 0 24px; font-size: 14px; } | ||
#message a { display: block; text-align: center; background: #039be5; text-transform: uppercase; text-decoration: none; color: white; padding: 16px; border-radius: 4px; } | ||
#message, #message a { box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); } | ||
#load { color: rgba(0,0,0,0.4); text-align: center; font-size: 13px; } | ||
@media (max-width: 600px) { | ||
body, #message { margin-top: 0; background: white; box-shadow: none; } | ||
body { border-top: 16px solid #ffa100; } | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<p>Hello World</p> | ||
<button id="login"> | ||
Login | ||
</button> | ||
|
||
<div id="sanity"> | ||
|
||
</div> | ||
|
||
<script src= | ||
"https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"> | ||
</script> | ||
|
||
<script> | ||
|
||
function setup(){ | ||
$('#login').click(function (){ | ||
location.href = "http://127.0.0.1:5001/majoraudit/us-central1/login"; | ||
}); | ||
} | ||
|
||
$('document').ready(setup); | ||
</script> | ||
</body> | ||
</html> | ||
</html> |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Welcome to Cloud Functions for Firebase for Python! | ||
# To get started, simply uncomment the below code or create your own. | ||
# Deploy with `firebase deploy` | ||
from urllib.request import urlopen | ||
|
||
from firebase_functions import https_fn | ||
from firebase_admin import initialize_app, auth | ||
from flask import redirect | ||
from xmltodict import parse | ||
|
||
initialize_app() | ||
|
||
|
||
@https_fn.on_request() | ||
def login(req: https_fn.Request) -> https_fn.Response: | ||
# response=https_fn.Response() | ||
|
||
redirect_url = '''https://secure.its.yale.edu/cas/login?service=http%3A%2F%2F127.0.0.1%3A5001%2Fmajoraudit%2Fus-central1%2Fvalidate''' | ||
return redirect(redirect_url) | ||
|
||
@https_fn.on_request() | ||
def validate(req: https_fn.Request) -> https_fn.Response: | ||
response=https_fn.Response() | ||
|
||
# redirect_url = '''https://secure.its.yale.edu/cas/login?service=http%3A%2F%2F127.0.0.1%3A5001%2Fmajoraudit%2Fus-central1%2Flogin''' | ||
if 'ticket' in req.args: | ||
val_url=f'''https://secure.its.yale.edu/cas/serviceValidate?service=http%3A%2F%2F127.0.0.1%3A5001%2Fmajoraudit%2Fus-central1%2Fvalidate&ticket={req.args['ticket']}''' | ||
|
||
xml_dump = urlopen(val_url).read().strip().decode('utf8', 'ignore') | ||
try: | ||
xml_dic = parse(xml_dump)["cas:serviceResponse"]["cas:authenticationSuccess"] | ||
username=xml_dic["cas:user"] | ||
resp=username | ||
except: | ||
resp='invalid CAS ticket' | ||
|
||
else: | ||
resp='no ticket found' | ||
return https_fn.Response(resp) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
firebase_functions~=0.1.0 | ||
xmltodict |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.