github.com/zooyer/miskit@v1.0.71/sdk/sso/sso_test.go (about)

     1  package sso
     2  
     3  import (
     4  	"net/http"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/gin-gonic/gin"
     9  )
    10  
    11  func TestSession(t *testing.T) {
    12  	engine := gin.Default()
    13  
    14  	var options = Option{
    15  		ClientID:     "5dbeab91e4904b7bae78b7e4408ceed7",
    16  		ClientSecret: "5f1766594bf8431d87a61c71f0f859e8",
    17  		Scope:        []string{"userinfo", "session"},
    18  		Addr:         "http://127.0.0.1:8801",
    19  		Retry:        2,
    20  		Timeout:      time.Second * 2,
    21  		Logger:       nil,
    22  	}
    23  
    24  	client := New(options)
    25  
    26  	var redirect = WithRedirect(func(ctx *gin.Context, uri string, err error) {
    27  		ctx.AbortWithStatusJSON(http.StatusUnauthorized, uri)
    28  	})
    29  
    30  	session := client.Session(engine, "/login", "/oauth", "/logout", redirect)
    31  	engine.GET("/", session, func(ctx *gin.Context) {
    32  		ctx.JSON(200, gin.H{
    33  			"errno":   0,
    34  			"message": "success",
    35  			"data":    client.SessionUserinfo(ctx),
    36  		})
    37  	})
    38  
    39  	panic(engine.Run())
    40  }