2015-03-13 04:20:36 +02:00
|
|
|
package authboss
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"golang.org/x/oauth2"
|
2015-09-11 16:03:05 +02:00
|
|
|
"golang.org/x/net/context"
|
2015-03-13 04:20:36 +02:00
|
|
|
)
|
|
|
|
|
2015-03-14 01:23:43 +02:00
|
|
|
/*
|
|
|
|
OAuth2Provider is the entire configuration
|
|
|
|
required to authenticate with this provider.
|
|
|
|
|
|
|
|
The OAuth2Config does not need a redirect URL because it will
|
2015-03-15 20:25:59 +02:00
|
|
|
be automatically created by the route registration in the oauth2 module.
|
2015-03-14 01:23:43 +02:00
|
|
|
|
|
|
|
AdditionalParams can be used to specify extra parameters to tack on to the
|
|
|
|
end of the initial request, this allows for provider specific oauth options
|
|
|
|
like access_type=offline to be passed to the provider.
|
|
|
|
|
|
|
|
Callback gives the config and the token allowing an http client using the
|
|
|
|
authenticated token to be created. Because each OAuth2 implementation has a different
|
|
|
|
API this must be handled for each provider separately. It is used to return two things
|
|
|
|
specifically: UID (the ID according to the provider) and the Email address.
|
|
|
|
The UID must be passed back or there will be an error as it is the means of identifying the
|
|
|
|
user in the system, e-mail is optional but should be returned in systems using
|
|
|
|
emailing. The keys authboss.StoreOAuth2UID and authboss.StoreEmail can be used to set
|
|
|
|
these values in the authboss.Attributes map returned by the callback.
|
2015-03-15 20:25:59 +02:00
|
|
|
|
|
|
|
In addition to the required values mentioned above any additional
|
|
|
|
values that you wish to have in your user struct can be included here, such as the
|
|
|
|
Name of the user at the endpoint. Keep in mind that only types that are valid for the
|
|
|
|
Attributes type should be used: string, bool, time.Time, int64, or any type that implements
|
|
|
|
database/driver.Valuer.
|
2015-03-14 01:23:43 +02:00
|
|
|
*/
|
2015-03-15 20:25:59 +02:00
|
|
|
type OAuth2Provider struct {
|
2015-03-13 04:20:36 +02:00
|
|
|
OAuth2Config *oauth2.Config
|
|
|
|
AdditionalParams url.Values
|
2015-09-11 16:03:05 +02:00
|
|
|
Callback func(context.Context, oauth2.Config, *oauth2.Token) (Attributes, error)
|
2015-03-13 04:20:36 +02:00
|
|
|
}
|