Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add basic CAS login api integration #10

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 46 additions & 45 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{
// "functions": [
// {
// "source": "functions",
// "codebase": "default",
// "ignore": [
// "venv",
// ".git",
// "firebase-debug.log",
// "firebase-debug.*.log"
// ]
// }
// ],
// "database": {
// "rules": "database.rules.json"
// },
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"venv",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
],
"requirements": "functions/requirements.txt"
}
],
"database": {
"rules": "database.rules.json"
},
"hosting": {
"public": "frontend",
"ignore": [
Expand All @@ -26,35 +27,35 @@
},
"storage": {
"rules": "storage.rules"
},
"emulators": {
"auth": {
"port": 9099
},
"functions": {
"port": 5001
},
"firestore": {
"port": 8080
},
"database": {
"port": 9000
},
"hosting": {
"port": 5000
},
"pubsub": {
"port": 8085
},
"storage": {
"port": 9199
},
"eventarc": {
"port": 9299
},
"ui": {
"enabled": true
},
"singleProjectMode": true
}
// "emulators": {
// "auth": {
// "port": 9099
// },
// "functions": {
// "port": 5001
// },
// "firestore": {
// "port": 8080
// },
// "database": {
// "port": 9000
// },
// "hosting": {
// "port": 5000
// },
// "pubsub": {
// "port": 8085
// },
// "storage": {
// "port": 9199
// },
// "eventarc": {
// "port": 9299
// },
// "ui": {
// "enabled": true
// },
// "singleProjectMode": true
// }
}
65 changes: 61 additions & 4 deletions frontend/index.html
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 added functions/.gitignore
Empty file.
39 changes: 39 additions & 0 deletions functions/main.py
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)
2 changes: 2 additions & 0 deletions functions/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
firebase_functions~=0.1.0
xmltodict
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading