inital google calendar integration
This commit is contained in:
parent
6195fbc456
commit
4f5a6e67af
@ -8,6 +8,8 @@ class Settings(BaseSettings):
|
||||
auth0_api_audience: str
|
||||
auth0_issuer: str
|
||||
auth0_algorithms: str
|
||||
google_client_id: str
|
||||
google_client_secret: str
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
|
@ -55,6 +55,9 @@ class PrintAction(BaseModel):
|
||||
# sentence (prints a custom message)
|
||||
sentence: str = ""
|
||||
|
||||
class GoogleUpdate(BaseModel):
|
||||
code: str
|
||||
|
||||
# @app.get("/api/public")
|
||||
# def public():
|
||||
# """No access token required to access this route"""
|
||||
@ -66,6 +69,10 @@ class PrintAction(BaseModel):
|
||||
# }
|
||||
# return result
|
||||
|
||||
@app.post("/api/google/update")
|
||||
def write_todos(code: GoogleUpdate, auth_result: str = Security(auth.verify)):
|
||||
print(code.code)
|
||||
return {"status": "success"}
|
||||
|
||||
@app.get('/api/first_run')
|
||||
def first_run():
|
||||
@ -101,7 +108,6 @@ def get_todos(date: str = datetime.today().strftime('%Y-%m-%d'), auth_result: st
|
||||
# return auth_result
|
||||
|
||||
|
||||
|
||||
@app.post("/api/todos/write")
|
||||
def write_todos(todos: TodoList, auth_result: str = Security(auth.verify)):
|
||||
"""A valid access token is required to access this route"""
|
||||
|
@ -18,6 +18,9 @@
|
||||
|
||||
</div>
|
||||
|
||||
<button onclick="client.requestCode();">Authorize with Google</button>
|
||||
|
||||
|
||||
<!-- <div id="testToken"></div> -->
|
||||
|
||||
|
||||
@ -446,6 +449,34 @@
|
||||
|
||||
</script>
|
||||
|
||||
<!-- Google auth for calendar access on first launch-->
|
||||
<script src="https://accounts.google.com/gsi/client"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
let code_receiver_uri = "/api/google/update"
|
||||
|
||||
const client = google.accounts.oauth2.initCodeClient({
|
||||
client_id: '186960779149-ejtu6hh3kdatlouau80h2pivt4tv3hd0.apps.googleusercontent.com',
|
||||
scope: 'https://www.googleapis.com/auth/calendar.readonly',
|
||||
ux_mode: 'popup',
|
||||
callback: (response) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', code_receiver_uri, true);
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.setRequestHeader('Authorization', 'Bearer ' + jToken);
|
||||
// Set custom header for CRSF
|
||||
xhr.setRequestHeader('X-Requested-With', 'XmlHttpRequest');
|
||||
xhr.onload = function() {
|
||||
console.log('Auth code response: ' + xhr.responseText);
|
||||
};
|
||||
xhr.send(JSON.stringify({"code": response.code}));
|
||||
console.log(xhr)
|
||||
console.log(response.code)
|
||||
},
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<script src="scripts.js"></script>
|
||||
</body>
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
# filename = os.path.abspath(os.path.join(WORKING_DIRECTORY, STATIC, 'index.html'))
|
||||
# with open(filename, 'rt') as f:
|
||||
# resp.body = f.read()
|
||||
from escpos.printer import Usb
|
||||
from escpos.printer import Usb, Dummy
|
||||
import usb
|
||||
from wonderwords import RandomWord
|
||||
from datetime import datetime
|
||||
@ -53,8 +53,9 @@ class ThermalPrinter():
|
||||
# pass
|
||||
except usb.core.NoBackendError as e:
|
||||
print(e)
|
||||
self.p = Dummy()
|
||||
print("Try running `export DYLD_LIBRARY_PATH=/opt/homebrew/lib` if on m1 mac. source: https://github.com/pyusb/pyusb/issues/355#issuecomment-1062798576")
|
||||
raise
|
||||
# raise
|
||||
|
||||
def print_custom(self, text=""):
|
||||
self.p.set(align="left")
|
||||
|
@ -19,3 +19,7 @@ sniffio==1.3.0
|
||||
typing_extensions==4.7.1
|
||||
uvicorn==0.23.2
|
||||
wonderwords
|
||||
google-api-python-client
|
||||
google-auth
|
||||
google-auth-oauthlib
|
||||
google-auth-httplib2
|
Loading…
Reference in New Issue
Block a user