New feature: Auth support for social networks, dropbox, amazon and so on. Untested

https://github.com/iris-contrib/goth/ is the main package which has been
converted to work with Iris from the ...
https://github.com/markbates/goth/ . Not yet tested on real application.
This commit is contained in:
Makis Maropoulos 2016-06-22 04:22:12 +03:00
parent 74bbc34d5b
commit 70b5e3d090
3 changed files with 53 additions and 14 deletions

View File

@ -11,6 +11,16 @@ import (
"encoding/json"
"encoding/xml"
"fmt"
"github.com/iris-contrib/formBinder"
"github.com/iris-contrib/goth"
"github.com/iris-contrib/goth/gothic"
"github.com/kataras/iris/config"
"github.com/kataras/iris/context"
"github.com/kataras/iris/errors"
"github.com/kataras/iris/sessions/store"
"github.com/kataras/iris/utils"
"github.com/klauspost/compress/gzip"
"github.com/valyala/fasthttp"
"html/template"
"io"
"net"
@ -22,15 +32,6 @@ import (
"strings"
"sync"
"time"
"github.com/iris-contrib/formBinder"
"github.com/kataras/iris/config"
"github.com/kataras/iris/context"
"github.com/kataras/iris/errors"
"github.com/kataras/iris/sessions/store"
"github.com/kataras/iris/utils"
"github.com/klauspost/compress/gzip"
"github.com/valyala/fasthttp"
)
const (
@ -781,3 +782,16 @@ func (ctx *Context) SendMail(subject string, body string, to ...string) error {
func (ctx *Context) Log(format string, a ...interface{}) {
ctx.framework.Logger.Printf(format, a...)
}
/* Auth */
// CompleteUserAuth does what it says on the tin. It completes the authentication
// process and fetches all of the basic information about the user from the provider.
//
// It expects to be able to get the name of the provider from the named parameters
// as either "provider" or ":provider".
//
// See https://github.com/iris-contrib/goth/examples/main.go to see this in action.
func (ctx *Context) CompleteUserAuth() (goth.User, error) {
return gothic.CompleteUserAuth(ctx)
}

View File

@ -2,12 +2,12 @@ package context
import (
"bufio"
"github.com/iris-contrib/goth"
"github.com/kataras/iris/sessions/store"
"github.com/valyala/fasthttp"
"html/template"
"io"
"time"
"github.com/kataras/iris/sessions/store"
"github.com/valyala/fasthttp"
)
type (
@ -18,6 +18,7 @@ type (
IContextBinder
IContextRequest
IContextResponse
IContextAuth
SendMail(string, string, ...string) error
Log(string, ...interface{})
Reset(*fasthttp.RequestCtx)
@ -131,4 +132,16 @@ type (
Session() store.IStore
SessionDestroy()
}
// IContextAuth handles the authentication/authorization
IContextAuth interface {
// CompleteUserAuth does what it says on the tin. It completes the authentication
// process and fetches all of the basic information about the user from the provider.
//
// It expects to be able to get the name of the provider from the named parameters
// as either "provider" or ":provider".
//
// See https://github.com/iris-contrib/goth/examples/main.go to see this in action.
CompleteUserAuth() (goth.User, error)
}
)

16
iris.go
View File

@ -59,10 +59,10 @@ import (
"strings"
"time"
"github.com/kataras/iris/errors"
"github.com/iris-contrib/goth/gothic"
"github.com/kataras/iris/config"
"github.com/kataras/iris/context"
"github.com/kataras/iris/errors"
"github.com/kataras/iris/utils"
"github.com/valyala/fasthttp"
)
@ -568,6 +568,18 @@ func (s *Framework) TemplateString(templateFile string, pageContext interface{},
return res
}
// BeginAuthHandler is a convienence handler for starting the authentication process.
// It expects to be able to get the name of the provider from the named parameters
// as either "provider" or ":provider".
//
// BeginAuthHandler will redirect the user to the appropriate authentication end-point
// for the requested provider.
//
// See https://github.com/iris-contrib/goth/examples/main.go to see this in action.
func BeginAuthHandler(ctx *Context) {
gothic.BeginAuthHandler(ctx)
}
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
// ----------------------------------MuxAPI implementation------------------------------