stormpath

package module
v0.0.0-...-1fc9397 Latest Latest
Warning

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

Go to latest
Published: May 2, 2015 License: Apache-2.0 Imports: 24 Imported by: 0

README

Go SDK for the Stormpath API

Develop:

Build Status Coverage Status

Master:

Build Status Coverage Status

#Usage

go get github.com/jarias/stormpath-sdk-go

import "github.com/jarias/stormpath-sdk-go"
import "fmt"

//This would look for env variables first STORMPATH_API_KEY_ID and STORMPATH_API_KEY_SECRET if empty
//then it would look for os.Getenv("HOME") + "/.config/stormpath/apiKey.properties" for the credentials
credentials, _ := stormpath.NewDefaultCredentials()

//Init Whithout cache
stormpath.Init(credentials, nil)

//Get the current tenant
tenant, _ := stormpath.CurrentTenant()

//Get the tenat applications
apps, _ := tenant.GetApplications(stormpath.NewDefaultPageRequest(), stormpath.NewEmptyFilter())

//Get the first application
app := apps.Items[0]

//Authenticate a user against the app
accountRef, _ := app.AuthenticateAccount("username", "password")

//Print the account information
account, _ := accountRef.GetAccount()
fmt.Println(account)

Features:

  • Cache with a sample Redis implementation
  • Almost 100% of the Stormpath API implemented
  • Load credentials via properties file or env variables
  • Requests are authenticated via Stormpath SAuthc1 algorithm

#License

Copyright 2014 Julio Arias

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Index

Constants

View Source
const (
	IDTerminator         = "sauthc1_request"
	AuthenticationScheme = "SAuthc1"
	NL                   = "\n"
	HostHeader           = "Host"
	AuthorizationHeader  = "Authorization"
	StormpathDateHeader  = "X-Stormpath-Date"
	Algorithm            = "HMAC-SHA-256"
	SAUTHC1Id            = "sauthc1Id"
	SAUTHC1SignedHeaders = "sauthc1SignedHeaders"
	SAUTHC1Signature     = "sauthc1Signature"
	DateFormat           = "20060102"
	TimestampFormat      = "20060102T150405Z0700"
)

SAuthc1 algorithm constants

Variables

View Source
var BaseURL = "https://api.stormpath.com/v1/"

BaseURL defines the Stormpath API base URL

View Source
var Logger *log.Logger

Functions

func Authenticate

func Authenticate(req *http.Request, payload []byte, date time.Time, credentials Credentials, nonce string)

Authenticate generates the proper authentication header for the SAuthc1 algorithm use by Stormpath

func Init

func Init(credentials Credentials, cache Cache)

Init initializes the underlying client that communicates with Stormpath

func InitWithCustomHTTPClient

func InitWithCustomHTTPClient(credentials Credentials, cache Cache, httpClient *http.Client)

InitWithCustomHTTPClient initializes the underlying client that communicates with Stormpath with a custom http.Client

func NewAccountFilter

func NewAccountFilter(givenName string, middleName string, surname string, username string, email string) url.Values

NewAccountFilter creates the url.Values for an account filter if any of the values is 0 len they won't be added to the values

func NewDefaultFilter

func NewDefaultFilter(name string, description string, status string) url.Values

NewDefaultFilter creates a new filter set of url.Values, default includes name, description and status

func NewDefaultPageRequest

func NewDefaultPageRequest() url.Values

NewDefaultPageRequest is a conviniece constructor for the default PageRequest values limit = 25 offset = 0

func NewEmptyFilter

func NewEmptyFilter() url.Values

NewEmptyFilter returns an empty url.Values{}

func NewPageRequest

func NewPageRequest(limit int, offset int) url.Values

NewPageRequest is a conviniece constructor for a PageRequest

Types

type Account

type Account struct {
	Href                   string `json:"href,omitempty"`
	Username               string `json:"username,omitempty"`
	Email                  string `json:"email"`
	Password               string `json:"password"`
	FullName               string `json:"fullName,omitempty"`
	GivenName              string `json:"givenName"`
	MiddleName             string `json:"middleName,omitempty"`
	Surname                string `json:"surname"`
	Status                 string `json:"status,omitempty"`
	CustomData             *link  `json:"customData,omitempty"`
	Groups                 *link  `json:"groups,omitempty"`
	GroupMemberships       *link  `json:"groupMemberships,omitempty"`
	Directory              *link  `json:"directory,omitempty"`
	Tenant                 *link  `json:"tenant,omitempty"`
	EmailVerificationToken *link  `json:"emailVerificationToken,omitempty"`
}

Account represents an Stormpath account object

See: http://docs.stormpath.com/rest/product-guide/#accounts

func NewAccount

func NewAccount(email string, password string, givenName string, surname string) *Account

NewAccount is a conviniece constructor for an Account, it accepts all the required fields according to the Stormpath API, it returns a pointer to an Account

func (*Account) AddToGroup

func (account *Account) AddToGroup(group *Group) (*GroupMembership, error)

AddToGroup adds the given account to a given group and returns the respective GroupMembership

func (*Account) Delete

func (account *Account) Delete() error

Delete deletes the given account, it wont modify the calling account

func (*Account) GetCustomData

func (account *Account) GetCustomData() (map[string]interface{}, error)

GetCustomData returns the given account custom data as a map

func (*Account) GetGroupMemberships

func (account *Account) GetGroupMemberships(pageRequest url.Values) (*GroupMemberships, error)

GetGroupMemberships returns a paged result of the group memeberships of the given account

func (*Account) RemoveFromGroup

func (account *Account) RemoveFromGroup(group *Group) error

RemoveFromGroup removes the given account from the given group by searching the account groupmemberships, and deleting the corresponding one

func (*Account) Save

func (account *Account) Save() error

Save updates the given account, by doing a POST to the account Href, if the account is a new account it should be created via Application.RegisterAccount

func (*Account) UpdateCustomData

func (account *Account) UpdateCustomData(data map[string]interface{}) error

UpdateCustomData sets or updates the given account custom data

type AccountPasswordResetToken

type AccountPasswordResetToken struct {
	Href    string
	Email   string
	Account link
}

AccountPasswordResetToken represents an password reset token for a given account

See: http://docs.stormpath.com/rest/product-guide/#application-accounts (Reset An Account’s Password)

type AccountRef

type AccountRef struct {
	Account link
}

AccountRef represent a link to an account, this type of resource is return when expand is not especify, use only in account authentication

See: http://docs.stormpath.com/rest/product-guide/#application-accounts (Log In (Authenticate) an Account)

func (*AccountRef) GetAccount

func (accountRef *AccountRef) GetAccount() (*Account, error)

GetAccount returns the Account from an AccountRef

type AccountStoreMapping

type AccountStoreMapping struct {
	Href                  string `json:"href,omitempty"`
	ListIndex             *int   `json:"listIndex,omitempty"`
	IsDefaultAccountStore *bool  `json:"isDefaultAccountStore,omitempty"`
	IsDefaultGroupStore   *bool  `json:"isDefaultGroupStore,omitempty"`
	Application           link   `json:"application"`
	AccountStore          link   `json:"accountStore"`
}

AccountStoreMapping represents an Stormpath account store mapping

See: http://docs.stormpath.com/rest/product-guide/#account-store-mappings

func NewAccountStoreMapping

func NewAccountStoreMapping(applicationHref string, accountStoreHref string) *AccountStoreMapping

NewAccountStoreMapping creates a new account store mappings

func (*AccountStoreMapping) Save

func (mapping *AccountStoreMapping) Save() error

Save saves the given account store mapping

type AccountStoreMappings

type AccountStoreMappings struct {
	Items []AccountStoreMapping `json:"items"`
	// contains filtered or unexported fields
}

AccountStoreMappings represents a pages result of account store mappings

See: http://docs.stormpath.com/rest/product-guide/#list-account-store-mappings

type Accounts

type Accounts struct {
	Items []Account `json:"items"`
	// contains filtered or unexported fields
}

Accounts represents a paged result of Account objects

See: http://docs.stormpath.com/rest/product-guide/#accounts-list

type Application

type Application struct {
	Href                       string `json:"href,omitempty"`
	Name                       string `json:"name"`
	Description                string `json:"description,omitempty"`
	Status                     string `json:"status,omitempty"`
	Accounts                   *link  `json:"accounts,omitempty"`
	Groups                     *link  `json:"groups,omitempty"`
	Tenant                     *link  `json:"tenant,omitempty"`
	PasswordResetTokens        *link  `json:"passwordResetTokens,omitempty"`
	AccountStoreMappings       *link  `json:"accountStoreMappings,omitempty"`
	DefaultAccountStoreMapping *link  `json:"defaultAccountStoreMapping,omitempty"`
	DefaultGroupStoreMapping   *link  `json:"defaultGroupStoreMapping,omitempty"`
}

Application represents a Stormpath application object

See: http://docs.stormpath.com/rest/product-guide/#applications

func NewApplication

func NewApplication(name string) *Application

NewApplication creates a new application

func (*Application) AuthenticateAccount

func (app *Application) AuthenticateAccount(username string, password string) (*AccountRef, error)

AuthenticateAccount authenticates an account against the application

See: http://docs.stormpath.com/rest/product-guide/#authenticate-an-account

func (*Application) CreateGroup

func (app *Application) CreateGroup(group *Group) error

CreateGroup creates a new group in the application

See: http://docs.stormpath.com/rest/product-guide/#application-groups

func (*Application) CreateIDSiteURL

func (app *Application) CreateIDSiteURL(options map[string]string) (string, error)

CreateIDSiteURL creates the IDSite URL for the application

func (*Application) Delete

func (app *Application) Delete() error

Delete deletes the given applicaiton

See: http://docs.stormpath.com/rest/product-guide/#delete-an-application

func (*Application) GetAccountStoreMappings

func (app *Application) GetAccountStoreMappings(pageRequest url.Values, filter url.Values) (*AccountStoreMappings, error)

GetAccountStoreMappings returns all the applications account store mappings

See: http://docs.stormpath.com/rest/product-guide/#application-account-store-mappings

func (*Application) GetAccounts

func (app *Application) GetAccounts(pageRequest url.Values, filter url.Values) (*Accounts, error)

GetAccounts returns all the accounts of the application

See: http://docs.stormpath.com/rest/product-guide/#application-accounts

func (*Application) GetGroups

func (app *Application) GetGroups(pageRequest url.Values, filter url.Values) (*Groups, error)

GetGroups returns all the application groups

See: http://docs.stormpath.com/rest/product-guide/#application-groups

func (*Application) HandleIDSiteCallback

func (app *Application) HandleIDSiteCallback(URL string) (*IDSiteCallbackResult, error)

HandleIDSiteCallback handles the URL from an ID Site callback it parses the JWT token validates it and return an IDSiteCallbackResult with the token info + the Account if the sub was given

func (*Application) Purge

func (app *Application) Purge() error

Purge deletes all the account stores before deleting the application

See: http://docs.stormpath.com/rest/product-guide/#delete-an-application

func (*Application) RegisterAccount

func (app *Application) RegisterAccount(account *Account) error

RegisterAccount registers a new account into the application

See: http://docs.stormpath.com/rest/product-guide/#application-accounts

func (*Application) RegisterSocialAccount

func (app *Application) RegisterSocialAccount(socialAccount *SocialAccount) (*Account, error)

RegisterSocialAccount registers a new account into the application using an external provider Google, Facebook

See: http://docs.stormpath.com/rest/product-guide/#accessing-accounts-with-google-authorization-codes-or-an-access-tokens

func (*Application) ResetPassword

func (app *Application) ResetPassword(token string, newPassword string) (*AccountRef, error)

ResetPassword resets a user password based on the reset token

See: http://docs.stormpath.com/rest/product-guide/#reset-an-accounts-password

func (*Application) SendPasswordResetEmail

func (app *Application) SendPasswordResetEmail(username string) (*AccountPasswordResetToken, error)

SendPasswordResetEmail sends a password reset email to the given user

See: http://docs.stormpath.com/rest/product-guide/#reset-an-accounts-password

func (*Application) ValidatePasswordResetToken

func (app *Application) ValidatePasswordResetToken(token string) (*AccountPasswordResetToken, error)

ValidatePasswordResetToken validates a password reset token

See: http://docs.stormpath.com/rest/product-guide/#reset-an-accounts-password

type ApplicationRef

type ApplicationRef struct {
	Application link
}

ApplicationRef holds the the Href of an application

func NewApplicationRef

func NewApplicationRef(href string) *ApplicationRef

NewApplicationRef creates an ApplicationHref from a URL

func (*ApplicationRef) GetApplication

func (applicationRef *ApplicationRef) GetApplication() (*Application, error)

GetApplication loads an application from the given ApplicationRef

type Applications

type Applications struct {
	Items []Application `json:"items"`
	// contains filtered or unexported fields
}

Applications represents a paged result or applications

type Cache

type Cache interface {
	Exists(key string) bool
	Set(key string, data interface{})
	Get(key string, result interface{}) error
	Del(key string)
}

Cache is a base interface for any cache provider

type Client

type Client struct {
	Credentials Credentials
	HTTPClient  *http.Client
	Cache       Cache
}

Client is low level REST client for any Stormpath request, it holds the credentials, an the actual http client, and the cache. The Cache can be initialize in nil and the client would simply ignore it and don't cache any response.

type Credentials

type Credentials struct {
	ID     string
	Secret string
}

Credentials represents a set of Stormpath credentials

func NewCredentialsFromFile

func NewCredentialsFromFile(file string) (Credentials, error)

NewCredentialsFromFile creates a new credentials from a Stormpath key files

func NewDefaultCredentials

func NewDefaultCredentials() (Credentials, error)

NewDefaultCredentials would create a new credentials based on env variables first then the default file location at ~/.config/stormpath/apiKey.properties

type Directories

type Directories struct {
	Items []Directory `json:"items"`
	// contains filtered or unexported fields
}

Directories represnets a paged result of directories

type Directory

type Directory struct {
	Href        string `json:"href,omitempty"`
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Status      string `json:"status,omitempty"`
	Accounts    *link  `json:"accounts,omitempty"`
	Groups      *link  `json:"groups,omitempty"`
	Tenant      *link  `json:"tenant,omitempty"`
}

Directory represents a Stormpath directory object

See: http://docs.stormpath.com/rest/product-guide/#directories

func NewDirectory

func NewDirectory(name string) *Directory

NewDirectory creates a new directory with the given name

func (*Directory) CreateGroup

func (dir *Directory) CreateGroup(group *Group) error

CreateGroup creates a new group in the directory

func (*Directory) Delete

func (dir *Directory) Delete() error

Delete deletes the directory

func (*Directory) GetAccounts

func (dir *Directory) GetAccounts(pageRequest url.Values, filter url.Values) (*Accounts, error)

GetAccounts returns all the accounts from the directory

func (*Directory) GetGroups

func (dir *Directory) GetGroups(pageRequest url.Values, filter url.Values) (*Groups, error)

GetGroups returns all the groups from a directory

func (*Directory) RegisterAccount

func (dir *Directory) RegisterAccount(account *Account) error

RegisterAccount registers a new account into the directory

See: http://docs.stormpath.com/rest/product-guide/#directory-accounts

func (*Directory) RegisterSocialAccount

func (dir *Directory) RegisterSocialAccount(socialAccount *SocialAccount) (*Account, error)

RegisterSocialAccount registers a new account into the application using an external provider Google, Facebook

See: http://docs.stormpath.com/rest/product-guide/#accessing-accounts-with-google-authorization-codes-or-an-access-tokens

func (*Directory) Save

func (dir *Directory) Save() error

Save saves the directory in Stormpath

type Group

type Group struct {
	Href        string `json:"href,omitempty"`
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Status      string `json:"status,omitempty"`
	CustomData  *link  `json:"customData,omitempty"`
	Accounts    *link  `json:"accounts,omitempty"`
	Tenant      *link  `json:"tenant,omitempty"`
	Directory   *link  `json:"directory,omitempty"`
}

Group represents a Stormpath Group

See: http://docs.stormpath.com/rest/product-guide/#groups

func NewGroup

func NewGroup(name string) *Group

NewGroup creates a new Group with the given name

func (*Group) Delete

func (group *Group) Delete() error

func (*Group) GetAccounts

func (group *Group) GetAccounts(pageRequest url.Values, filter url.Values) (*Accounts, error)

func (*Group) GetGroupMemberships

func (group *Group) GetGroupMemberships(pageRequest url.Values, filter url.Values) (*GroupMemberships, error)

func (*Group) Save

func (group *Group) Save() error

type GroupMembership

type GroupMembership struct {
	Href    string `json:"href,omitempty"`
	Account link   `json:"account"`
	Group   link   `json:"group"`
}

func NewGroupMembership

func NewGroupMembership(accountHref string, groupHref string) *GroupMembership

func (*GroupMembership) Delete

func (groupmembership *GroupMembership) Delete() error

func (*GroupMembership) GetAccount

func (groupmembership *GroupMembership) GetAccount() (*Account, error)

func (*GroupMembership) GetGroup

func (groupmembership *GroupMembership) GetGroup() (*Group, error)

type GroupMemberships

type GroupMemberships struct {
	Items []GroupMembership `json:"items"`
	// contains filtered or unexported fields
}

type Groups

type Groups struct {
	Items []Groups `json:"items"`
	// contains filtered or unexported fields
}

Groups represent a paged result of groups

type IDSiteCallbackResult

type IDSiteCallbackResult struct {
	Account *Account
	State   string
	IsNew   bool
	Status  string
}

IDSiteCallbackResult holds the ID Site callback parsed JWT token information + the acccount if one was given

type PageRequest

type PageRequest struct {
	Limit  int
	Offset int
}

PageRequest contains the limit and offset values for any paginated Stormpath request

type ProviderData

type ProviderData struct {
	ProviderId  string `json:"providerId"`
	AccessToken string `json:"accessToken"`
}

type RedisCache

type RedisCache struct {
	Conn redis.Conn
}

RedisCache is the default provided implementation of the Cache interface using Redis as backend

func (RedisCache) Del

func (r RedisCache) Del(key string)

Del deletes a key from the cache

func (RedisCache) Exists

func (r RedisCache) Exists(key string) bool

Exists returns true if the key exists in the cache false otherwise

func (RedisCache) Get

func (r RedisCache) Get(key string, result interface{}) error

Get returns the data store under key it should return an error if any occur

func (RedisCache) Set

func (r RedisCache) Set(key string, data interface{})

Set stores data in the the cache for the given key

type SocialAccount

type SocialAccount struct {
	Data ProviderData `json:"providerData"`
}

type Tenant

type Tenant struct {
	Href         string `json:"href"`
	Name         string `json:"name"`
	Key          string `json:"key"`
	CustomData   link   `json:"customData"`
	Applications link   `json:"applications"`
	Directories  link   `json:"directories"`
}

Tenant represents a Stormpath tennat see http://docs.stormpath.com/rest/product-guide/#tenants

func CurrentTenant

func CurrentTenant() (*Tenant, error)

CurrentTenant returns the current tenant see http://docs.stormpath.com/rest/product-guide/#retrieve-the-current-tenant

func (*Tenant) CreateApplication

func (tenant *Tenant) CreateApplication(app *Application) error

CreateApplication creates a new application for the given tenant

See: http://docs.stormpath.com/rest/product-guide/#tenant-applications

func (*Tenant) CreateDirectory

func (tenant *Tenant) CreateDirectory(dir *Directory) error

CreateDirectory creates a new directory for the given tenant

See: http://docs.stormpath.com/rest/product-guide/#tenant-directories

func (*Tenant) DeleteCustomData

func (tenant *Tenant) DeleteCustomData() error

DeleteCustomData deletes all the tenants custom data

See: http://docs.stormpath.com/rest/product-guide/#custom-data

func (*Tenant) GetApplications

func (tenant *Tenant) GetApplications(pageRequest url.Values, filter url.Values) (*Applications, error)

GetApplications returns all the applications for the given tenant

See: http://docs.stormpath.com/rest/product-guide/#tenant-applications

func (*Tenant) GetCustomData

func (tenant *Tenant) GetCustomData() (map[string]interface{}, error)

GetCustomData gets the tenant custom data map

See: http://docs.stormpath.com/rest/product-guide/#custom-data

func (*Tenant) GetDirectories

func (tenant *Tenant) GetDirectories(pageRequest url.Values, filter url.Values) (*Directories, error)

GetDirectories returns all the directories for the given tenant

See: http://docs.stormpath.com/rest/product-guide/#tenant-directories

func (*Tenant) UpdateCustomData

func (tenant *Tenant) UpdateCustomData(customData map[string]interface{}) (map[string]interface{}, error)

UpdateCustomData updates the tenant custom data and returns that updated custom data as a map[string]interface

See: http://docs.stormpath.com/rest/product-guide/#custom-data

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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