Child pages
  • Authentication Package
Skip to end of metadata
Go to start of metadata

The package linksmart.eu/lc/sec/auth provides interfaces to obtain and validate service tickets.
Below are a few examples on how it can be used in third-party services and clients.


Obtainer package
// Setup ticket obtainer
    to, err := obtainer.Setup("cas", c.ServerAddr)
    if err != nil {
        fmt.Println(err.Error())
        return
    }

    // Get Ticket Granting Ticket
    TGT, err := to.Login(c.Username, c.Password)
    if err != nil {
        fmt.Println(err.Error())
        return
    }

    // Get Service Ticket
    serviceTicket, err := to.RequestTicket(TGT, c.ServiceID)
    if err != nil {
        fmt.Println(err.Error())
        return
    }

    // Logout
    err := to.Logout(TGT)
    if err != nil {
        fmt.Println(err.Error())
        return
    }
Using obtainer client
    // Setup ticket obtainer
    to, err := obtainer.Setup("cas", c.ServerAddr)
    if err != nil {
        fmt.Println(err.Error())
        return
    }

    // Ticker obtainer client
    ticket, err := obtainer.NewClient("cas", c.ServerAddr, c.Username, c.Password, c.ServiceID)
    if err != nil {
        fmt.Println(err.Error())
        return
    }

    // Obtain a new ticket
    t, err := ticket.Obtain()
    if err != nil {
        fmt.Println(err.Error())
        return
    }

    // Renew the ticket
    t, err = ticket.Renew()
    if err != nil {
        fmt.Println(err.Error())
        return
    }

    // Delete the ticket
    err = ticket.Delete()
    if err != nil {
        fmt.Println(err.Error())
        return
    }
Validator package
    // Setup ticket validator
    // c.Authz contains authorization rules (set to nil, if not required).
    tv, err := validator.Setup("cas", c.ServerAddr, c.ServiceID, &c.Authz)
    if err != nil {
        fmt.Println(err.Error())
        return
    }

    // Validate Service Ticket
    valid, attr, err := tv.Validate(serviceTicket)
    if err != nil {
        fmt.Println(err.Error())
        return
    }
Using the handler
    // Setup ticket validator
    tv, err := validator.Setup("cas", c.ServerAddr, c.ServiceID, nil)
    if err != nil {
        fmt.Println(err.Error())
        return
    }

    // Appending to an alice chain of HTTP middleware functions
    existingChain = existingChain.Append(tv.Handler)
  • No labels