kitwalk

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2019 License: GPL-3.0 Imports: 9 Imported by: 0

README

StudioAquatan/kitwalk

CircleCI codecov Go Report Card

This package will support your automation in your student life with a program written in golang.

Package http/net is very useful and generally used in many situations. http.Client is a standard method to access website or send API request ...etc, so kitwalk is just a wrapper to get authenticated cookies and store it to your own http.Client.

Just create http.Client instance, and give it to this package, now you can access the website protected with Shibboleth using http.Client.

Environment

  • Go 1.10 or later

Other packages

Usage

See example

NOTE

Shibboleth authentication will revoke after few hours. If the website require to authenticate again, you should use LoginWith again. If you logged in and the website require to re-authenticate, LoginWith cannot works well, I think. So, this package only support

  1. Short life cycle work
    • For example, scraping every minutes, CLI tool, ... etc.
    • You should clear the cookie properly and periodically if your program run for a long time.
  2. No re-authentication
    • I don't know such a situation will occur, kitwalk doesn't support that.
    • For example, in other services, re-auth is required when you change password or perform administrative activity.

Please be careful to use. DON'T PUSH YOUR USERNAME OR PASSWORD TO YOUR REPOSITORY.

Development

We welcome your contribution! Please commit any fix or improvement.

To fix version of packages, you should use dep.

  • Dep v0.5.0 or later
Release
  1. Write documents
    • examples/main.go
    • README.md
  2. git commit -a -m 'Release v${VERSION}'
  3. git tag v${VERSION}
  4. git push origin master --tags

License

GPL v3

Author

  • StudioAquatan
    • pudding

Documentation

Index

Constants

View Source
const (
	// DefaultUnameKey is used to post auth information
	DefaultUnameKey = "j_username"
	// DefaultPasswdKey is used as well as DefaultUnameKey
	DefaultPasswdKey = "j_password"
	// DefaultRelayStateKey is the key to parse HTML and extract saml auth information.
	DefaultRelayStateKey = "RelayState"
	// DefaultSAMLResponseKey is used as well as DefaultRelayStateKey
	DefaultSAMLResponseKey = "SAMLResponse"
	// DefaultAuthDomain is the domain of auth server.
	DefaultAuthDomain = "auth.cis.kit.ac.jp"
	// ShibbolethLoginURL is the default login url.
	ShibbolethLoginURL = "https://portal.student.kit.ac.jp/"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth interface {
	LoginWith(client *http.Client) error
	SetupWith(config Config) error
	LoginAs(username string, password string) error
}

Auth is an interface for http.Client

func NewAuthenticator

func NewAuthenticator(ctx context.Context, username string, password string) (Auth, error)

NewAuthenticator create new authenticator with given auth information.

type Config

type Config struct {
	// Username key is used when this module POST auth information to auth server.
	ShibbolethUsernameKey string
	// Password key is used as well as Username key.
	ShibbolethPasswordKey string
	// Domain information of auth server.
	ShibbolethAuthDomain string
	// Url to login
	ShibbolethLoginURL string
	// This params has an additionally information to auth.
	// POST with username and password.
	ShibbolethHiddenParams url.Values
	// When appear webstorage confirmation during authentication steps, this params send to the server.
	ShibbolethPassConfirmationParams url.Values
}

Config struct will have settings for saml authentication.

func GetDefaultConfig

func GetDefaultConfig() *Config

GetDefaultConfig will return the default configuration. It is enough to authenticate typically.

type ConfigDoesNotExists

type ConfigDoesNotExists struct{}

ConfigDoesNotExists will raise when some configurations are missing.

func (*ConfigDoesNotExists) Error

func (e *ConfigDoesNotExists) Error() string

type InvalidUsernameError

type InvalidUsernameError struct {
	// contains filtered or unexported fields
}

InvalidUsernameError will be return when given user name is invalid.

func (*InvalidUsernameError) Error

func (e *InvalidUsernameError) Error() string

type SamlAuthenticator

type SamlAuthenticator struct {
	User   *User
	Config Config
	// contains filtered or unexported fields
}

SamlAuthenticator has Config and User. This struct implement Auth interface.

func (*SamlAuthenticator) LoginAs

func (c *SamlAuthenticator) LoginAs(username string, password string) error

LoginAs switch user to authenticate with

func (*SamlAuthenticator) LoginWith

func (c *SamlAuthenticator) LoginWith(client *http.Client) error

LoginWith works with given http.Client to auth. The client store cookie information to be used for next authentication.

func (*SamlAuthenticator) SetupWith

func (c *SamlAuthenticator) SetupWith(config Config) error

SetupWith attach given configuration to authenticator.

type ShibbolethAuthError

type ShibbolethAuthError struct {
	// contains filtered or unexported fields
}

ShibbolethAuthError will raise when authentication has been failed.

func (*ShibbolethAuthError) Error

func (e *ShibbolethAuthError) Error() string

type User

type User struct {
	Username string
	Password string
}

User is an user belonging to the authentication destination

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL