MCPcopy Create free account
hub / github.com/rilldata/rill / IssueMagicAuthToken

Method IssueMagicAuthToken

admin/auth_token.go:192–227  ·  view source on GitHub ↗

IssueMagicAuthToken generates and persists a new magic auth token for a project.

(ctx context.Context, opts *IssueMagicAuthTokenOptions)

Source from the content-addressed store, hash-verified

190
191// IssueMagicAuthToken generates and persists a new magic auth token for a project.
192func (s *Service) IssueMagicAuthToken(ctx context.Context, opts *IssueMagicAuthTokenOptions) (AuthToken, error) {
193 for mv := range opts.MetricsViewFilterJSONs {
194 if mv == "" {
195 return nil, fmt.Errorf("metrics view name cannot be empty in MetricsViewFilterJSONs")
196 }
197 }
198
199 tkn := authtoken.NewRandom(authtoken.TypeMagic)
200
201 var expiresOn *time.Time
202 if opts.TTL != nil {
203 t := time.Now().Add(*opts.TTL)
204 expiresOn = &t
205 }
206
207 dat, err := s.DB.InsertMagicAuthToken(ctx, &database.InsertMagicAuthTokenOptions{
208 ID: tkn.ID.String(),
209 SecretHash: tkn.SecretHash(),
210 Secret: tkn.Secret[:],
211 ProjectID: opts.ProjectID,
212 ExpiresOn: expiresOn,
213 CreatedByUserID: opts.CreatedByUserID,
214 Attributes: opts.Attributes,
215 MetricsViewFilterJSONs: opts.MetricsViewFilterJSONs,
216 Fields: opts.Fields,
217 State: opts.State,
218 DisplayName: opts.DisplayName,
219 Internal: opts.Internal,
220 Resources: opts.Resources,
221 })
222 if err != nil {
223 return nil, err
224 }
225
226 return &magicAuthToken{model: dat, token: tkn}, nil
227}
228
229// ExtendBrowserSessionAuthToken extends a Rill web browser session token when its
230// remaining lifetime is at or below refreshThreshold.

Callers

nothing calls this directly

Calls 6

NewRandomFunction · 0.92
SecretHashMethod · 0.80
ErrorfMethod · 0.65
AddMethod · 0.65
InsertMagicAuthTokenMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected