Makis Maropoulos 2016-06-22 12:45:57 +03:00
parent e6bc24b648
commit 56f78567a2
5 changed files with 24 additions and 26 deletions

View File

@ -112,7 +112,7 @@ func main() {
func myAuthMiddleware(c *iris.Context) { func myAuthMiddleware(c *iris.Context) {
s := c.Session() s := c.Session()
if s.GetString("username") == "myusername" && s.GetString("passowrd") == "mypassword" { if s.GetString("username") == "myusername" && s.GetString("password") == "mypassword" {
c.Next() c.Next()
} else { } else {
c.EmitError(iris.StatusUnauthorized) c.EmitError(iris.StatusUnauthorized)

View File

@ -11,3 +11,4 @@ Third party packages
- [formam as form binder](https://github.com/monoculum/formam) - [formam as form binder](https://github.com/monoculum/formam)
- [i18n for internalization](https://github.com/Unknwon/i18n) - [i18n for internalization](https://github.com/Unknwon/i18n)
- [color for banner](https://github.com/fatih/color) - [color for banner](https://github.com/fatih/color)
- [gothic](https://github.com/iris-contrib/gothic)/[goth for Multi-Provider OAuth, OAuth2](https://github.com/markbates/goth)

View File

@ -11,16 +11,6 @@ import (
"encoding/json" "encoding/json"
"encoding/xml" "encoding/xml"
"fmt" "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" "html/template"
"io" "io"
"net" "net"
@ -32,6 +22,17 @@ import (
"strings" "strings"
"sync" "sync"
"time" "time"
"github.com/iris-contrib/formBinder"
"github.com/iris-contrib/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/markbates/goth"
"github.com/valyala/fasthttp"
) )
const ( const (
@ -789,9 +790,9 @@ func (ctx *Context) Log(format string, a ...interface{}) {
// process and fetches all of the basic information about the user from the provider. // 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 // It expects to be able to get the name of the provider from the named parameters
// as either "provider" or ":provider". // as either "provider" or url query parameter ":provider".
// //
// See https://github.com/iris-contrib/goth/examples/main.go to see this in action. // See https://github.com/iris-contrib/gothic/blob/master/example/main.go to see this in action.
func (ctx *Context) CompleteUserAuth() (goth.User, error) { func (ctx *Context) CompleteUserAuth() (goth.User, error) {
return gothic.CompleteUserAuth(ctx) return gothic.CompleteUserAuth(ctx)
} }

View File

@ -2,12 +2,13 @@ package context
import ( import (
"bufio" "bufio"
"github.com/iris-contrib/goth"
"github.com/kataras/iris/sessions/store"
"github.com/valyala/fasthttp"
"html/template" "html/template"
"io" "io"
"time" "time"
"github.com/kataras/iris/sessions/store"
"github.com/markbates/goth"
"github.com/valyala/fasthttp"
) )
type ( type (
@ -135,13 +136,8 @@ type (
// IContextAuth handles the authentication/authorization // IContextAuth handles the authentication/authorization
IContextAuth interface { IContextAuth interface {
// CompleteUserAuth does what it says on the tin. It completes the authentication // CompleteUserAuth
// process and fetches all of the basic information about the user from the provider. // See https://github.com/iris-contrib/gothic/blob/master/example/main.go to see this in action.
//
// 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) CompleteUserAuth() (goth.User, error)
} }
) )

View File

@ -59,7 +59,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/iris-contrib/goth/gothic" "github.com/iris-contrib/gothic"
"github.com/kataras/iris/config" "github.com/kataras/iris/config"
"github.com/kataras/iris/context" "github.com/kataras/iris/context"
"github.com/kataras/iris/errors" "github.com/kataras/iris/errors"
@ -570,12 +570,12 @@ func (s *Framework) TemplateString(templateFile string, pageContext interface{},
// BeginAuthHandler is a convienence handler for starting the authentication process. // 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 // It expects to be able to get the name of the provider from the named parameters
// as either "provider" or ":provider". // as either "provider" or url query parameter ":provider".
// //
// BeginAuthHandler will redirect the user to the appropriate authentication end-point // BeginAuthHandler will redirect the user to the appropriate authentication end-point
// for the requested provider. // for the requested provider.
// //
// See https://github.com/iris-contrib/goth/examples/main.go to see this in action. // See https://github.com/iris-contrib/gothic/blob/master/example/main.go to see this in action.
func BeginAuthHandler(ctx *Context) { func BeginAuthHandler(ctx *Context) {
gothic.BeginAuthHandler(ctx) gothic.BeginAuthHandler(ctx)
} }