- $signer_uri = $profile->getUri();
- if (empty($signer_uri)) {
- throw new ServerException(sprintf('Profile missing URI (id==%d)', $profile->id));
- }
- $magicsig = $this->discoverKeyPair($signer_uri);
+ // Throws exception on failure, but does not try to _load_ the keypair string.
+ $keypair = $this->discoverKeyPair($profile);
+
+ $magicsig = new Magicsig();
+ $magicsig->user_id = $profile->id;
+ $magicsig->importKeys($keypair);
+ // save the public key for this profile in our database.
+ // TODO: If the profile generates a new key remotely, we must be able to replace
+ // this (of course after callback-verification).
+ $magicsig->insert();