forked from jarias/stormpath-sdk-go
/
social.go
36 lines (27 loc) · 879 Bytes
/
social.go
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
31
32
33
34
35
36
package stormpathweb
import (
"net/http"
"github.com/jarias/stormpath-sdk-go"
"golang.org/x/net/context"
)
const socialAccount = "socialAccount"
type defaultSocialHandler struct {
Application *stormpath.Application
LoginHandler loginHandler
}
func (h defaultSocialHandler) authenticateSocial(w http.ResponseWriter, r *http.Request, ctx context.Context, socialAccount *stormpath.SocialAccount) {
account, err := h.Application.RegisterSocialAccount(socialAccount)
if err != nil {
context.WithValue(ctx, "error", buildErrorModel(err))
h.LoginHandler.doGET(w, r, ctx)
return
}
err = saveAuthenticationResult(w, r, transientAuthenticationResult(account), h.Application)
if err != nil {
context.WithValue(ctx, "error", buildErrorModel(err))
h.LoginHandler.doGET(w, r, ctx)
return
}
http.Redirect(w, r, Config.LoginNextURI, http.StatusFound)
return
}