{"id":16112963,"url":"https://github.com/guilospanck/macaroon","last_synced_at":"2025-04-06T07:23:36.578Z","repository":{"id":179949027,"uuid":"664010674","full_name":"Guilospanck/macaroon","owner":"Guilospanck","description":"Simple implementation of Macaroon for learning purposes.","archived":false,"fork":false,"pushed_at":"2023-07-23T17:00:53.000Z","size":58,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-12T12:55:45.083Z","etag":null,"topics":["authorisation","hmac-sha256","macaroons"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Guilospanck.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-07-08T17:14:22.000Z","updated_at":"2023-07-09T17:25:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"f6a1a080-1d7a-4993-b686-2100125a9d00","html_url":"https://github.com/Guilospanck/macaroon","commit_stats":null,"previous_names":["guilospanck/macaroon"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Guilospanck%2Fmacaroon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Guilospanck%2Fmacaroon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Guilospanck%2Fmacaroon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Guilospanck%2Fmacaroon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Guilospanck","download_url":"https://codeload.github.com/Guilospanck/macaroon/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247446799,"owners_count":20940179,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["authorisation","hmac-sha256","macaroons"],"created_at":"2024-10-09T20:09:50.904Z","updated_at":"2025-04-06T07:23:36.557Z","avatar_url":"https://github.com/Guilospanck.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Macaroon [![codecov](https://codecov.io/gh/Guilospanck/macaroon/branch/main/graph/badge.svg?token=xVQ6o2ZpM6)](https://codecov.io/gh/Guilospanck/macaroon)\n\nSimple implementation of macaroons as described in the paper [\"Macaroons: Cookies with Contextual Caveats for Decentralized Authorization in the Cloud\"](http://theory.stanford.edu/~ataly/Papers/macaroons.pdf).\n\n## How to use\n\n- Creating a macaroon\n\n```rs\nuse macaroon::{Macaroon, Verifier};\n\nlet root_key = \"potato\";\nlet identifier = \"test-id\";\nlet location = Some(\"https://macaroon.location\");\nlet mut original_macaroon = Macaroon::create(root_key, identifier, location);\n```\n\n- Adding caveats\n\n```rs\n// Adds 1st party caveat to the original macaroon\nlet predicate_account_id = \"account_id = 007\";\noriginal_macaroon.add_first_party_caveat(predicate_account_id);\n\n// Adds 3rd party caveat to the original macaroon\nlet caveat_discharge_location = Some(\"https://auth.bank\");\nlet caveat_identifier = \"caveat-identifier\";\nlet caveat_root_key = \"caveat-root-key\";\n\noriginal_macaroon.add_third_party_caveat(\n  caveat_root_key,\n  caveat_identifier,\n  caveat_discharge_location,\n);\n```\n\n- Create macaroon to discharge 3rd party caveat and bound it to the autorisation (original) macaroon\n\n```rs\n// Creates the discharge macaroon that will be responsible for\n// handling the 3rd party caveat just created.\nlet mut discharge_macaroon = Macaroon::create(\n  caveat_root_key,\n  caveat_identifier,\n  caveat_discharge_location,\n);\nlet first_party_caveat_of_discharge_macaroon_identifier = \"time \u003c 2023-07-09T00:00:00Z\";\ndischarge_macaroon.add_first_party_caveat(first_party_caveat_of_discharge_macaroon_identifier);\n\n// Bind the discharge to the original macaroon\nlet mut bound_macaroon = discharge_macaroon.clone();\nbound_macaroon.signature =\n  original_macaroon.bind_for_request(discharge_macaroon.signature.clone());\n\nlet expected_bound_signature = Macaroon::get_bound_signature(\n  discharge_macaroon.clone().signature,\n  original_macaroon.clone().signature,\n);\n\nassert_eq!(bound_macaroon.signature, expected_bound_signature);\n```\n\n- Verify macaroons\n\n```rs\nlet mut verifier = Verifier::default();\n// must satisfy first caveat from the original macaroon\nverifier.satisfy_exact(predicate_account_id);\n// must satisfy the first caveat from the discharge macaroon\nverifier.satisfy_exact(first_party_caveat_of_discharge_macaroon_identifier);\n\n// get verified result from discharge macaroon that DOES NOT have the signature bound to the authorisation macaroon\nlet discharge_macaroon_with_signature_not_bound_to_authorisation_macaroon_verifier = verifier\n  .verify(\n    original_macaroon.clone(),\n    root_key,\n    vec![discharge_macaroon],\n    None,\n  );\n\nassert!(\n  discharge_macaroon_with_signature_not_bound_to_authorisation_macaroon_verifier.is_err()\n);\nassert_eq!(\n  discharge_macaroon_with_signature_not_bound_to_authorisation_macaroon_verifier\n    .err()\n    .unwrap(),\n  VerifyError::SignaturesDoNotMatch\n);\n\n// get verified result from discharge macaroon that DOES have the signature bound to the authorisation macaroon\nlet discharge_macaroon_with_signature_bound_to_authorisation_macaroon_verifier =\n  verifier.verify(original_macaroon, root_key, vec![bound_macaroon], None);\n\nassert!(discharge_macaroon_with_signature_bound_to_authorisation_macaroon_verifier.is_ok());\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguilospanck%2Fmacaroon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguilospanck%2Fmacaroon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguilospanck%2Fmacaroon/lists"}