tangled
alpha
login
or
join now
willdot.net
/
cocoon
forked from
hailey.at/cocoon
0
fork
atom
An atproto PDS written in Go
0
fork
atom
overview
issues
pulls
pipelines
show ip for oauth sessions
hailey.at
8 months ago
44de733c
45b83afc
+6
-1
5 changed files
expand all
collapse all
unified
split
oauth
provider
models.go
server
handle_account.go
handle_oauth_authorize.go
handle_oauth_token.go
templates
account.html
+2
oauth/provider/models.go
···
65
65
Code string `gorm:"index"`
66
66
Token string `gorm:"uniqueIndex"`
67
67
RefreshToken string `gorm:"uniqueIndex"`
68
68
+
Ip string
68
69
}
69
70
70
71
type OauthAuthorizationRequest struct {
···
78
79
Sub *string
79
80
Code *string
80
81
Accepted *bool
82
82
+
Ip string
81
83
}
+1
server/handle_account.go
···
44
44
"UpdatedAt": t.CreatedAt.Format("02 Jan 06 15:04 MST"),
45
45
"ExpiresAt": t.CreatedAt.Format("02 Jan 06 15:04 MST"),
46
46
"Token": t.Token,
47
47
+
"Ip": t.Ip,
47
48
})
48
49
}
49
50
+1
-1
server/handle_oauth_authorize.go
···
113
113
114
114
code := oauth.GenerateCode()
115
115
116
116
-
if err := s.db.Exec("UPDATE oauth_authorization_requests SET sub = ?, code = ?, accepted = ? WHERE request_id = ?", nil, repo.Repo.Did, code, true, reqId).Error; err != nil {
116
116
+
if err := s.db.Exec("UPDATE oauth_authorization_requests SET sub = ?, code = ?, accepted = ?, ip = ? WHERE request_id = ?", nil, repo.Repo.Did, code, true, e.RealIP(), reqId).Error; err != nil {
117
117
s.logger.Error("error updating authorization request", "error", err)
118
118
return helpers.ServerError(e, nil)
119
119
}
+1
server/handle_oauth_token.go
···
157
157
Code: *authReq.Code,
158
158
Token: accessString,
159
159
RefreshToken: refreshToken,
160
160
+
Ip: authReq.Ip,
160
161
}, nil).Error; err != nil {
161
162
s.logger.Error("error creating token in db", "error", err)
162
163
return helpers.ServerError(e, nil)
+1
server/templates/account.html
···
28
28
<p>Created: {{ .CreatedAt }}</p>
29
29
<p>Updated: {{ .UpdatedAt }}</p>
30
30
<p>Expires: {{ .ExpiresAt }}</p>
31
31
+
<p>IP Address: {{ .Ip }}</p>
31
32
<form action="/account/revoke" method="post">
32
33
<input type="hidden" name="token" value="{{ .Token }}" />
33
34
<button type="submit" value="">Revoke</button>