func newUAAConnector(cfg *UAAConnectorConfig, uaaBaseURL *url.URL, cbURL string) (oauth2Connector, error) { uaaAuthURL := *uaaBaseURL uaaTokenURL := *uaaBaseURL uaaAuthURL.Path = path.Join(uaaAuthURL.Path, "/oauth/authorize") uaaTokenURL.Path = path.Join(uaaTokenURL.Path, "/oauth/token") config := oauth2.Config{ Credentials: oauth2.ClientCredentials{ID: cfg.ClientID, Secret: cfg.ClientSecret}, AuthURL: uaaAuthURL.String(), TokenURL: uaaTokenURL.String(), Scope: []string{"openid"}, AuthMethod: oauth2.AuthMethodClientSecretPost, RedirectURL: cbURL, } cli, err := oauth2.NewClient(http.DefaultClient, config) if err != nil { return nil, err } return &uaaOAuth2Connector{ clientID: cfg.ClientID, clientSecret: cfg.ClientSecret, client: cli, uaaBaseURL: uaaBaseURL, }, nil }
func (c *Client) OAuthClient() (*oauth2.Client, error) { authMethod, err := c.chooseAuthMethod() if err != nil { return nil, err } ocfg := oauth2.Config{ Credentials: oauth2.ClientCredentials(c.credentials), RedirectURL: c.redirectURL, AuthURL: c.providerConfig.AuthEndpoint, TokenURL: c.providerConfig.TokenEndpoint, Scope: c.scope, AuthMethod: authMethod, } return oauth2.NewClient(c.httpClient, ocfg) }
func newBitbucketConnector(clientID, clientSecret, cbURL string) (oauth2Connector, error) { config := oauth2.Config{ Credentials: oauth2.ClientCredentials{ID: clientID, Secret: clientSecret}, AuthURL: bitbucketAuthURL, TokenURL: bitbucketTokenURL, AuthMethod: oauth2.AuthMethodClientSecretPost, RedirectURL: cbURL, } cli, err := oauth2.NewClient(http.DefaultClient, config) if err != nil { return nil, err } return &bitbucketOAuth2Connector{ clientID: clientID, clientSecret: clientSecret, client: cli, }, nil }
func newFacebookConnector(clientID, clientSecret, cbURL string) (oauth2Connector, error) { config := oauth2.Config{ Credentials: oauth2.ClientCredentials{ID: clientID, Secret: clientSecret}, AuthURL: facebookConnectorAuthURL, TokenURL: facebookTokenURL, AuthMethod: oauth2.AuthMethodClientSecretPost, RedirectURL: cbURL, Scope: []string{"email"}, } cli, err := oauth2.NewClient(http.DefaultClient, config) if err != nil { return nil, err } return &facebookOAuth2Connector{ clientID: clientID, clientSecret: clientSecret, client: cli, }, nil }