diff --git a/.gitignore b/.gitignore index a2a3040..41c11c4 100755 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,8 @@ build/ ### VS Code ### .vscode/ + + +### Python ### +__pycache__ +.pytest_cache \ No newline at end of file diff --git a/README.md b/README.md index f63f125..88386c8 100755 --- a/README.md +++ b/README.md @@ -20,11 +20,22 @@ server.port=1285 ``` Następnym krokiem jest odpalenie poniższych komend w terminalu. + ``` cd restservice mvn spring-boot:run ``` +## Token + +Żeby tesotwać API wpełni potrzebny nam jest token który otrzymujemy na podstawie ticketa z systemu autoryzacyjnego **CAS**. Z tego powodu system autoryzacji działa inaczej niż w "książkowych" restowych aplikacjach i np Postman za nas jej nie dokona. Musimy mu podać już uzyskany token. Aby łatwo go uzyskać odpal skrypt + +``` +python gettoken.py +``` + +Na koniec w przęglądarce dostaniesz w odpowiedzi token. W samym pliku można zmienić porty aplikacji jeśli to potrzebne. + ## Packaging Zeby spakowac apke do `jara` wystarcza dwie komendy zaczynajac z glownego katalogu projektu diff --git a/gettoken.py b/gettoken.py new file mode 100755 index 0000000..31b18da --- /dev/null +++ b/gettoken.py @@ -0,0 +1,39 @@ +import webbrowser +from http.server import BaseHTTPRequestHandler, HTTPServer, SimpleHTTPRequestHandler +import urllib.parse as urlparse +from urllib.parse import parse_qs +import sys +import requests as r + +API_ADDRESS = "http://localhost:1285" +PORT = 3000 + + +class S(BaseHTTPRequestHandler): + def _set_response(self): + self.send_response(200) + self.send_header('Content-type', 'text/html') + self.end_headers() + + def do_GET(self): + parsed = urlparse.urlparse(str(self.path)) + ticket = str(parse_qs(parsed.query)['ticket'][0]) + print(ticket) + response = r.get(API_ADDRESS + "/token?ticket=" + ticket) + self._set_response() + self.wfile.write("Your token: {}".format( + response.text).encode('utf-8')) + + +def wait_for_request(server_class=HTTPServer, + handler_class=S): + server_address = ('localhost', PORT) + httpd = server_class(server_address, handler_class) + return httpd.handle_request() + + +url = 'https://cas.amu.edu.pl/cas/login?service=http://localhost:' + \ + str(PORT) + '&locale=pl' + +webbrowser.open_new_tab(url) +wait_for_request() diff --git a/pom.xml b/pom.xml index 790c301..c450fc3 100755 --- a/pom.xml +++ b/pom.xml @@ -2,11 +2,11 @@ 4.0.0 - org.springframework.boot - spring-boot-starter-parent - 2.2.2.RELEASE - - + org.springframework.boot + spring-boot-starter-parent + 2.2.2.RELEASE + + com.plannaplan backend @@ -78,7 +78,7 @@ - + buisnesslogic restservice