{"id":15138154,"url":"https://github.com/helloimalemur/rocket-sqlx-authentication-api-example","last_synced_at":"2026-01-18T23:33:21.068Z","repository":{"id":187752240,"uuid":"677510536","full_name":"helloimalemur/rocket-sqlx-authentication-api-example","owner":"helloimalemur","description":"An authentication api example written in Rust, using the Rocket framework.","archived":false,"fork":false,"pushed_at":"2023-10-12T15:35:46.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-06T06:44:42.270Z","etag":null,"topics":["api","auth-api","authentication","authentication-api","authentication-backend","rocket","rocket-rust","rust","rust-rocket"],"latest_commit_sha":null,"homepage":"https://koonts.net/articles/protected-api-with-rocket","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/helloimalemur.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-11T19:00:55.000Z","updated_at":"2023-08-13T01:39:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"d9e517f7-b33f-4873-b696-6d76fc315cde","html_url":"https://github.com/helloimalemur/rocket-sqlx-authentication-api-example","commit_stats":null,"previous_names":["helloimalemur/rocket-sqlx-authentication-api-example"],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/helloimalemur/rocket-sqlx-authentication-api-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helloimalemur%2Frocket-sqlx-authentication-api-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helloimalemur%2Frocket-sqlx-authentication-api-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helloimalemur%2Frocket-sqlx-authentication-api-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helloimalemur%2Frocket-sqlx-authentication-api-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/helloimalemur","download_url":"https://codeload.github.com/helloimalemur/rocket-sqlx-authentication-api-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helloimalemur%2Frocket-sqlx-authentication-api-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28553516,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T23:10:22.888Z","status":"ssl_error","status_checked_at":"2026-01-18T23:07:19.656Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","auth-api","authentication","authentication-api","authentication-backend","rocket","rocket-rust","rust","rust-rocket"],"created_at":"2024-09-26T07:20:56.921Z","updated_at":"2026-01-18T23:33:21.054Z","avatar_url":"https://github.com/helloimalemur.png","language":"Rust","readme":"## Session based auth\n    Implement authentication by storing the logged in user's session id into a cookie. If a user is present with the session cookie, then this user is authenticated. If there isn’t a valid cookie present, then we aren’t currently authenticated. We can store additional data into the session as needed, such as the user’s set of permissions or anything else that is potentially useful. Typically session IDs are transmitted by header, or by injecting them into the URL.\n\n## Create database\n```sql\nCREATE DATABASE testing;\n```\n\n## Create tables needed in the Database;\n```sql\nCREATE TABLE `users` (`id` int(11) NOT NULL AUTO_INCREMENT,\n`username` varchar(255) NOT NULL,\n`password` varchar(255) NOT NULL,\n`email` varchar(255) NOT NULL,\n`first_name` varchar(255) NOT NULL,\n`last_name` varchar(255) NOT NULL,\nPRIMARY KEY (`id`));\n```\n\n```sql\nCREATE TABLE `web_sessions` (`id` int(11) NOT NULL AUTO_INCREMENT,\n`user_name` varchar(255) NOT NULL,\n`session_id` varchar(255) NOT NULL,\n`date_created` varchar(255) NOT NULL,\nPRIMARY KEY (`id`));\n```\n\n## Create database user\n```sql\nCREATE USER 'dev'@'%' IDENTIFIED WITH sha256_password BY 'password';\nCREATE USER 'dev'@'%' IDENTIFIED BY 'password';\nGRANT ALL PRIVILEGES ON testing.* TO 'dev'@'%';\nFLUSH PRIVILEGES;\n```\n\n## Edit config/Settings.toml\n```toml\ndatabase_url = \"mysql://dev:password@localhost:3306/testing\"\ndatabase_name = \"testing\"\napi_key = \"yourapikey\"\n```\n\n## test and dev functions;\n```shell\n# create user;\ncurl -XPOST -H 'Content-Type:application/json' -H 'x-api-key:yourapikey' http://127.0.0.1:8030/api/adduser -d '{\"username\": \"foxx\",\"password\": \"doxx\",\"email\": \"test\",\"first_name\": \"test\",\"last_name\": \"test\"}'\n```\n\n```shell\n# login;\ncurl -XPOST -H 'Content-Type:application/json' http://127.0.0.1:8030/api/login -d '{\"username\": \"foxx\",\"password\": \"doxx\",\"ipaddress\": \"0.0.0.0\"}'\n```\n```shell\n# verify user / get username by session;\ncurl -XGET -H 'x-api-key:yourapikey' http://127.0.0.1:8030/api/\u003csession_id\u003e\n```\n```shell\n# verify session;\ncurl -XGET http://127.0.0.1:8030/api/verify/sessionid\n```\n```shell\n# logout;\ncurl -XGET http://127.0.0.1:8030/api/logout/\u003csession_id\u003e\n```\n\n## functions to be created for later;\n    delete user\n    modify user (change password)\n\n### Resources\n    https://www.baeldung.com/cs/tokens-vs-sessions\n    https://api.rocket.rs/v0.4/rocket/http/enum.Cookies.html\n    https://api.rocket.rs/v0.4/rocket/request/trait.FromRequest.html\n    https://rocket.rs/v0.5-rc/guide/requests/#custom-guards\n    https://api.rocket.rs/v0.5-rc/rocket/request/trait.FromRequest.html\n    https://stackoverflow.com/questions/69377336/how-to-get-state-in-fromrequest-implementation-with-rocket\n    https://stackoverflow.com/questions/73868771/rust-rocket-with-sqlx-test-database-endpoints\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhelloimalemur%2Frocket-sqlx-authentication-api-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhelloimalemur%2Frocket-sqlx-authentication-api-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhelloimalemur%2Frocket-sqlx-authentication-api-example/lists"}