-
-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82d2544
commit b6c6230
Showing
8 changed files
with
164 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package user | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// PublicKeyGETHandler should be served at eg https://example.org/users/:username/main-key. | ||
// | ||
// The goal here is to return a MINIMAL activitypub representation of an account | ||
// in the form of a vocab.ActivityStreamsPerson. The account will only contain the id, | ||
// public key, username, and type of the account. | ||
func (m *Module) PublicKeyGETHandler(c *gin.Context) { | ||
l := m.log.WithFields(logrus.Fields{ | ||
"func": "PublicKeyGETHandler", | ||
"url": c.Request.RequestURI, | ||
}) | ||
|
||
requestedUsername := c.Param(UsernameKey) | ||
if requestedUsername == "" { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": "no username specified in request"}) | ||
return | ||
} | ||
|
||
// make sure this actually an AP request | ||
format := c.NegotiateFormat(ActivityPubAcceptHeaders...) | ||
if format == "" { | ||
c.JSON(http.StatusNotAcceptable, gin.H{"error": "could not negotiate format with given Accept header(s)"}) | ||
return | ||
} | ||
l.Tracef("negotiated format: %s", format) | ||
|
||
// make a copy of the context to pass along so we don't break anything | ||
cp := c.Copy() | ||
user, err := m.processor.GetFediUser(requestedUsername, cp.Request) // GetFediUser handles auth as well | ||
if err != nil { | ||
l.Info(err.Error()) | ||
c.JSON(err.Code(), gin.H{"error": err.Safe()}) | ||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, user) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters