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