11package msc3861
22
33import (
4- "cmp"
54 "context"
65 "database/sql"
76 "encoding/json"
@@ -15,6 +14,7 @@ import (
1514 "github.com/element-hq/dendrite/clientapi/auth"
1615 "github.com/element-hq/dendrite/setup/config"
1716 "github.com/element-hq/dendrite/userapi/api"
17+ "github.com/matrix-org/gomatrixserverlib/fclient"
1818 "github.com/matrix-org/gomatrixserverlib/spec"
1919 "github.com/matrix-org/util"
2020)
@@ -45,7 +45,7 @@ type MSC3861UserVerifier struct {
4545 userAPI api.UserInternalAPI
4646 serverName spec.ServerName
4747 cfg * config.MSC3861
48- httpClient * http .Client
48+ httpClient * fclient .Client
4949 openIdConfig * OpenIDConfiguration
5050 allowGuest bool
5151}
@@ -55,13 +55,21 @@ func newMSC3861UserVerifier(
5555 serverName spec.ServerName ,
5656 cfg * config.MSC3861 ,
5757 allowGuest bool ,
58- httpClient * http .Client ,
58+ client * fclient .Client ,
5959) (* MSC3861UserVerifier , error ) {
60- client := cmp .Or (httpClient , http .DefaultClient )
60+ if cfg == nil {
61+ return nil , errors .New ("unable to create MSC3861UserVerifier object as 'cfg' param is nil" )
62+ }
63+
64+ if client == nil {
65+ return nil , errors .New ("unable to create MSC3861UserVerifier object as 'client' param is nil" )
66+ }
67+
6168 openIdConfig , err := fetchOpenIDConfiguration (client , cfg .Issuer )
6269 if err != nil {
6370 return nil , err
6471 }
72+
6573 return & MSC3861UserVerifier {
6674 userAPI : userAPI ,
6775 serverName : serverName ,
@@ -342,14 +350,14 @@ func (m *MSC3861UserVerifier) introspectToken(ctx context.Context, token string)
342350 req .Header .Add ("Content-Type" , "application/x-www-form-urlencoded" )
343351 req .SetBasicAuth (m .cfg .ClientID , m .cfg .ClientSecret )
344352
345- resp , err := m .httpClient .Do ( req )
353+ resp , err := m .httpClient .DoHTTPRequest ( ctx , req )
346354 if err != nil {
347355 return nil , err
348356 }
349357 body := resp .Body
350358 defer resp .Body .Close () // nolint: errcheck
351359
352- if c := resp .StatusCode ; c < 200 || c >= 300 {
360+ if c := resp .StatusCode ; c / 100 != 2 {
353361 return nil , errors .New (strings .Join ([]string {"The introspection endpoint returned a '" , resp .Status , "' response" }, "" ))
354362 }
355363 var ir introspectionResponse
@@ -394,13 +402,17 @@ type OpenIDConfiguration struct {
394402 AccountManagementActionsSupported []string `json:"account_management_actions_supported"`
395403}
396404
397- func fetchOpenIDConfiguration (httpClient * http .Client , authHostURL string ) (* OpenIDConfiguration , error ) {
405+ func fetchOpenIDConfiguration (httpClient * fclient .Client , authHostURL string ) (* OpenIDConfiguration , error ) {
398406 u , err := url .Parse (authHostURL )
399407 if err != nil {
400408 return nil , err
401409 }
402410 u = u .JoinPath (".well-known/openid-configuration" )
403- resp , err := httpClient .Get (u .String ())
411+ req , err := http .NewRequest (http .MethodGet , u .String (), nil )
412+ if err != nil {
413+ return nil , err
414+ }
415+ resp , err := httpClient .DoHTTPRequest (context .Background (), req )
404416 if err != nil {
405417 return nil , err
406418 }
0 commit comments