-
Notifications
You must be signed in to change notification settings - Fork 0
/
oauth.go
43 lines (35 loc) · 879 Bytes
/
oauth.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
37
38
39
40
41
42
43
package controllers
import (
"github.com/creativelikeadog/revel-oauth/app"
"github.com/creativelikeadog/revel-oauth/app/strategies"
"github.com/revel/revel"
)
type OAuth struct {
*revel.Controller
provider strategies.Strategy
}
func (c *OAuth) Auth(code string) revel.Result {
if code == "" {
return c.Redirect(c.provider.OnFailure())
}
if user, err := c.provider.Authorize(code); err != nil {
c.Flash.Error(err.Error())
return c.Redirect(c.provider.OnFailure())
} else {
oauth.Login(c.Controller, user)
return c.Redirect(c.provider.OnSuccess())
}
return c.Redirect(c.provider.OnFailure())
}
func (c *OAuth) Provider() revel.Result {
p := c.Params.Get("provider")
cfg := oauth.Providers[p]
if cfg != nil {
c.provider = cfg
return nil
}
return c.NotFound("Not found")
}
func init() {
revel.InterceptMethod((*OAuth).Provider, revel.BEFORE)
}