mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-16 18:43:10 -06:00
Fix clientapi for the OAuth2 OIDC refactoring in b8ac83f.
This commit is contained in:
parent
098fb12575
commit
59a327da19
|
|
@ -22,8 +22,9 @@ import (
|
|||
|
||||
func newGitHubIdentityProvider(cfg *config.IdentityProvider, hc *http.Client) identityProvider {
|
||||
return &oauth2IdentityProvider{
|
||||
cfg: cfg,
|
||||
hc: hc,
|
||||
cfg: cfg,
|
||||
oauth2Cfg: &cfg.OAuth2,
|
||||
hc: hc,
|
||||
|
||||
authorizationURL: "https://github.com/login/oauth/authorize",
|
||||
accessTokenURL: "https://github.com/login/oauth/access_token",
|
||||
|
|
|
|||
|
|
@ -31,8 +31,9 @@ import (
|
|||
)
|
||||
|
||||
type oauth2IdentityProvider struct {
|
||||
cfg *config.IdentityProvider
|
||||
hc *http.Client
|
||||
cfg *config.IdentityProvider
|
||||
oauth2Cfg *config.OAuth2
|
||||
hc *http.Client
|
||||
|
||||
authorizationURL string
|
||||
accessTokenURL string
|
||||
|
|
@ -48,7 +49,7 @@ type oauth2IdentityProvider struct {
|
|||
|
||||
func (p *oauth2IdentityProvider) AuthorizationURL(ctx context.Context, callbackURL, nonce string) (string, error) {
|
||||
u, err := resolveURL(p.authorizationURL, url.Values{
|
||||
"client_id": []string{p.cfg.OAuth2.ClientID},
|
||||
"client_id": []string{p.oauth2Cfg.ClientID},
|
||||
"response_type": []string{"code"},
|
||||
"redirect_uri": []string{callbackURL},
|
||||
"scope": []string{strings.Join(p.scopes, " ")},
|
||||
|
|
@ -121,8 +122,8 @@ func (p *oauth2IdentityProvider) getAccessToken(ctx context.Context, callbackURL
|
|||
"grant_type": []string{"authorization_code"},
|
||||
"code": []string{code},
|
||||
"redirect_uri": []string{callbackURL},
|
||||
"client_id": []string{p.cfg.OAuth2.ClientID},
|
||||
"client_secret": []string{p.cfg.OAuth2.ClientSecret},
|
||||
"client_id": []string{p.oauth2Cfg.ClientID},
|
||||
"client_secret": []string{p.oauth2Cfg.ClientSecret},
|
||||
}
|
||||
hreq, err := http.NewRequestWithContext(ctx, http.MethodPost, p.accessTokenURL, strings.NewReader(body.Encode()))
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ func TestOAuth2IdentityProviderAuthorizationURL(t *testing.T) {
|
|||
|
||||
authorizationURL: "https://oauth2.example.com/authorize",
|
||||
}
|
||||
idp.oauth2Cfg = &idp.cfg.OAuth2
|
||||
|
||||
got, err := idp.AuthorizationURL(ctx, "https://matrix.example.com/continue", "anonce")
|
||||
if err != nil {
|
||||
|
|
@ -98,6 +99,7 @@ func TestOAuth2IdentityProviderProcessCallback(t *testing.T) {
|
|||
displayNamePath: "name",
|
||||
suggestedUserIDPath: "preferred_user",
|
||||
}
|
||||
idp.oauth2Cfg = &idp.cfg.OAuth2
|
||||
|
||||
got, err := idp.ProcessCallback(ctx, callbackURL, "anonce", tst.Query)
|
||||
if err != nil {
|
||||
|
|
@ -145,6 +147,7 @@ func TestOAuth2IdentityProviderGetAccessToken(t *testing.T) {
|
|||
|
||||
accessTokenURL: s.URL + "/token",
|
||||
}
|
||||
idp.oauth2Cfg = &idp.cfg.OAuth2
|
||||
|
||||
got, err := idp.getAccessToken(ctx, callbackURL, "acode")
|
||||
if err != nil {
|
||||
|
|
@ -198,6 +201,7 @@ func TestOAuth2IdentityProviderGetUserInfo(t *testing.T) {
|
|||
displayNamePath: "name",
|
||||
suggestedUserIDPath: "preferred_user",
|
||||
}
|
||||
idp.oauth2Cfg = &idp.cfg.OAuth2
|
||||
|
||||
gotSub, gotName, gotSuggestedUser, err := idp.getUserInfo(ctx, "atoken")
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -50,8 +50,9 @@ type oidcIdentityProvider struct {
|
|||
func newOIDCIdentityProvider(cfg *config.IdentityProvider, hc *http.Client) *oidcIdentityProvider {
|
||||
return &oidcIdentityProvider{
|
||||
oauth2IdentityProvider: &oauth2IdentityProvider{
|
||||
cfg: cfg,
|
||||
hc: hc,
|
||||
cfg: cfg,
|
||||
oauth2Cfg: &cfg.OIDC.OAuth2,
|
||||
hc: hc,
|
||||
|
||||
scopes: []string{"openid", "profile", "email"},
|
||||
responseMimeType: "application/json",
|
||||
|
|
|
|||
|
|
@ -26,10 +26,10 @@ func TestOIDCIdentityProviderAuthorizationURL(t *testing.T) {
|
|||
defer s.Close()
|
||||
|
||||
idp := newOIDCIdentityProvider(&config.IdentityProvider{
|
||||
OAuth2: config.OAuth2{
|
||||
ClientID: "aclientid",
|
||||
},
|
||||
OIDC: config.OIDC{
|
||||
OAuth2: config.OAuth2{
|
||||
ClientID: "aclientid",
|
||||
},
|
||||
DiscoveryURL: s.URL + "/discovery",
|
||||
},
|
||||
}, s.Client())
|
||||
|
|
@ -97,10 +97,10 @@ func TestOIDCIdentityProviderProcessCallback(t *testing.T) {
|
|||
|
||||
sURL = s.URL
|
||||
idp := newOIDCIdentityProvider(&config.IdentityProvider{
|
||||
OAuth2: config.OAuth2{
|
||||
ClientID: "aclientid",
|
||||
},
|
||||
OIDC: config.OIDC{
|
||||
OAuth2: config.OAuth2{
|
||||
ClientID: "aclientid",
|
||||
},
|
||||
DiscoveryURL: sURL + "/discovery",
|
||||
},
|
||||
}, s.Client())
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@ func TestNewAuthenticator(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Type: config.SSOTypeOIDC,
|
||||
OAuth2: config.OAuth2{
|
||||
ClientID: "aclientid",
|
||||
},
|
||||
OIDC: config.OIDC{
|
||||
OAuth2: config.OAuth2{
|
||||
ClientID: "aclientid",
|
||||
},
|
||||
DiscoveryURL: "http://oidc.example.com/discovery",
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue