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 --invite-base-url option for customizing the URL used in connection invitations #197

Merged
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
3 changes: 2 additions & 1 deletion aries_cloudagent/conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ async def start(self) -> None:
),
public=context.settings.get("debug.invite_public", False)
)
invite_url = invitation.to_url()
base_url = context.settings.get("invite_base_url")
invite_url = invitation.to_url(base_url)
print("Invitation URL:")
print(invite_url)
except Exception:
Expand Down
8 changes: 8 additions & 0 deletions aries_cloudagent/config/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,12 @@ def add_arguments(self, parser: ArgumentParser):
connection response is accepted. Some agents require this before\
marking a connection as 'active'. Default: false.",
)
parser.add_argument(
"--invite-base-url",
type=str,
metavar="<base-url>",
help="Base URL to use when formatting connection invitations in URL format."
)
parser.add_argument(
"--public-invites",
action="store_true",
Expand All @@ -512,6 +518,8 @@ def get_settings(self, args: Namespace) -> dict:
settings["external_protocols"] = args.external_protocols
if args.auto_ping_connection:
settings["auto_ping_connection"] = True
if args.invite_base_url:
settings["invite_base_url"] = args.invite_base_url
if args.public_invites:
settings["public_invites"] = True
if args.timing:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(
self.endpoint = endpoint
self.routing_keys = list(routing_keys) if routing_keys else None

def to_url(self) -> str:
def to_url(self, base_url: str = None) -> str:
"""
Convert an invitation to URL format for sharing.

Expand All @@ -63,7 +63,7 @@ def to_url(self) -> str:
"""
c_json = self.to_json()
c_i = bytes_to_b64(c_json.encode("ascii"), urlsafe=True)
result = urljoin(self.endpoint, "?c_i={}".format(c_i))
result = urljoin(base_url or self.endpoint or "", "?c_i={}".format(c_i))
return result

@classmethod
Expand Down
3 changes: 2 additions & 1 deletion aries_cloudagent/messaging/connections/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ async def connections_create_invitation(request: web.BaseRequest):

if public and not context.settings.get("public_invites"):
raise web.HTTPForbidden()
base_url = context.settings.get("invite_base_url")

connection_mgr = ConnectionManager(context)
connection, invitation = await connection_mgr.create_invitation(
Expand All @@ -202,7 +203,7 @@ async def connections_create_invitation(request: web.BaseRequest):
result = {
"connection_id": connection and connection.connection_id,
"invitation": invitation.serialize(),
"invitation_url": invitation.to_url(),
"invitation_url": invitation.to_url(base_url),
}

if connection and connection.alias:
Expand Down