summaryrefslogtreecommitdiffstats
path: root/services/externalaccount/link.go
blob: d6e2ea7e9427c108534a54c29d54f8345bf321c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright 2021 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package externalaccount

import (
	"context"
	"fmt"

	user_model "code.gitea.io/gitea/models/user"

	"github.com/markbates/goth"
)

// Store represents a thing that stores things
type Store interface {
	Get(any) any
	Set(any, any) error
	Release() error
}

// LinkAccountFromStore links the provided user with a stored external user
func LinkAccountFromStore(ctx context.Context, store Store, user *user_model.User) error {
	gothUser := store.Get("linkAccountGothUser")
	if gothUser == nil {
		return fmt.Errorf("not in LinkAccount session")
	}

	return LinkAccountToUser(ctx, user, gothUser.(goth.User))
}