// New validates and creates a new authenticate service from a set of Options
New validates and creates a new authenticate service from a set of Options
// New validates and creates a new authenticate service from a set of Options
func New(opts *Options) (*Authenticate, error) {
	if opts == nil {
		return nil, errors.New("authenticate: options cannot be nil")
	}
	if err := opts.Validate(); err != nil {
		return nil, err
	}
	decodedCookieSecret, _ := base64.StdEncoding.DecodeString(opts.CookieSecret)
	cipher, err := cryptutil.NewCipher([]byte(decodedCookieSecret))
	if err != nil {
		return nil, err
	}
	cookieStore, err := sessions.NewCookieStore(
		&sessions.CookieStoreOptions{
			Name:           opts.CookieName,
			CookieSecure:   opts.CookieSecure,
			CookieHTTPOnly: opts.CookieHTTPOnly,
			CookieExpire:   opts.CookieExpire,
			CookieCipher:   cipher,
		})
	if err != nil {
		return nil, err
	}
	redirectURL := opts.AuthenticateURL
	redirectURL.Path = "/oauth2/callback"
	provider, err := identity.New(
		opts.Provider,
		&identity.Provider{
			RedirectURL:    redirectURL,
			ProviderName:   opts.Provider,
			ProviderURL:    opts.ProviderURL,
			ClientID:       opts.ClientID,
			ClientSecret:   opts.ClientSecret,
			Scopes:         opts.Scopes,
			ServiceAccount: opts.ServiceAccount,
		})
	if err != nil {
		return nil, err
	}
	return &Authenticate{
		SharedKey:    opts.SharedKey,
		RedirectURL:  redirectURL,
		templates:    templates.New(),
		csrfStore:    cookieStore,
		sessionStore: cookieStore,
		cipher:       cipher,
		provider:     provider,
	}, nil
}
func New ( opts * Options ) ( * Authenticate , error ) { if opts == nil { return nil , errors . New ( " " ) } if err := opts . Validate ( ) ; err != nil { return nil , err } decodedCookieSecret , _ := base64 . StdEncoding . DecodeString ( opts . CookieSecret ) cipher , err := cryptutil . NewCipher ( [ ] byte ( decodedCookieSecret ) ) if err != nil { return nil , err } cookieStore , err := sessions . NewCookieStore ( & sessions . CookieStoreOptions { Name : opts . CookieName , CookieSecure : opts . CookieSecure , CookieHTTPOnly : opts . CookieHTTPOnly , CookieExpire : opts . CookieExpire , CookieCipher : cipher , } ) if err != nil { return nil , err } redirectURL := opts . AuthenticateURL redirectURL . Path = " " provider , err := identity . New ( opts . Provider , & identity . Provider { RedirectURL : redirectURL , ProviderName : opts . Provider , ProviderURL : opts . ProviderURL , ClientID : opts . ClientID , ClientSecret : opts . ClientSecret , Scopes : opts . Scopes , ServiceAccount : opts . ServiceAccount , } ) if err != nil { return nil , err } return & Authenticate { SharedKey : opts . SharedKey , RedirectURL : redirectURL , templates : templates . New ( ) , csrfStore : cookieStore , sessionStore : cookieStore , cipher : cipher , provider : provider , } , nil }
New validates and creates a new authenticate service from a set of Options
New validates and creates a new authenticate service from a set of Options