github.com/decred/politeia@v1.4.0/politeiawww/plugin/v1/authmanager.go (about) 1 // Copyright (c) 2022 The Decred developers 2 // Use of this source code is governed by an ISC 3 // license that can be found in the LICENSE file. 4 5 package v1 6 7 // AuthManager provides user authorization for plugin commands. 8 // 9 // Any changes made to the Session or User during method execution will be 10 // persisted by the caller. 11 type AuthManager interface { 12 // ID returns the plugin ID. 13 ID() string 14 15 // Version returns the lowest supported plugin API version. 16 Version() uint32 17 18 // Authorize checks if the user is authorized to execute a plugin command. 19 // 20 // A UserError is returned if the user is not authorized. 21 Authorize(AuthorizeArgs) error 22 } 23 24 // AuthorizeArgs contains the arguments for the Authorize method. 25 type AuthorizeArgs struct { 26 Session *Session 27 User *User 28 PluginID string 29 Version uint32 // Plugin API version 30 Cmd string 31 } 32 33 // Session contains the data that is saved as part of a user session. 34 // 35 // Plugins do not have direct access to the sessions database, but the 36 // AuthManager plugin is able to update fields on this session struct. Updates 37 // are saved to the sessions database by the backend. 38 type Session struct { 39 UserID string 40 CreatedAt int64 41 42 // Delete can be set by the AuthManager plugin to instruct the backend to 43 // delete the session. 44 Delete bool 45 }