Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use authenticate endpoint for x #3833

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/client-go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
15 changes: 11 additions & 4 deletions selfservice/strategy/oidc/provider_x.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"fmt"
"net/http"

"github.com/ory/x/otelx"

"github.com/dghubble/oauth1"
"github.com/dghubble/oauth1/twitter"
"github.com/pkg/errors"
Expand Down Expand Up @@ -54,20 +56,25 @@
return oauth1.NewToken(accessToken, accessSecret), nil
}

func (p *ProviderX) AuthURL(ctx context.Context, state string) (string, error) {
func (p *ProviderX) AuthURL(ctx context.Context, state string) (_ string, err error) {
ctx, span := p.reg.Tracer(ctx).Tracer().Start(ctx, "selfservice.strategy.oidc.ProviderLinkedIn.fetch")
defer otelx.End(span, &err)

Check warning on line 61 in selfservice/strategy/oidc/provider_x.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_x.go#L59-L61

Added lines #L59 - L61 were not covered by tests

c := p.OAuth1(ctx)

// We need to cheat so that callback validates on return
c.CallbackURL = c.CallbackURL + fmt.Sprintf("?state=%s&code=unused", state)

requestToken, _, err := c.RequestToken()
if err != nil {
return "", errors.WithStack(herodot.ErrInternalServerError.WithReasonf(`Unable to sign in with X because the OAuth1 request token could not be initialized.`))
span.RecordError(err)
return "", errors.WithStack(herodot.ErrInternalServerError.WithWrap(err).WithReasonf(`Unable to sign in with X because the OAuth1 request token could not be initialized: %s`, err))

Check warning on line 71 in selfservice/strategy/oidc/provider_x.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_x.go#L70-L71

Added lines #L70 - L71 were not covered by tests
}

authzURL, err := c.AuthorizationURL(requestToken)
if err != nil {
return "", errors.WithStack(herodot.ErrInternalServerError.WithReasonf(`Unable to sign in with X because the OAuth1 authorization URL could not be parsed.`))
span.RecordError(err)
return "", errors.WithStack(herodot.ErrInternalServerError.WithWrap(err).WithReasonf(`Unable to sign in with X because the OAuth1 authorization URL could not be parsed: %s`, err))

Check warning on line 77 in selfservice/strategy/oidc/provider_x.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_x.go#L76-L77

Added lines #L76 - L77 were not covered by tests
}

return authzURL.String(), nil
Expand All @@ -85,7 +92,7 @@
return &oauth1.Config{
ConsumerKey: p.config.ClientID,
ConsumerSecret: p.config.ClientSecret,
Endpoint: twitter.AuthorizeEndpoint,
Endpoint: twitter.AuthenticateEndpoint,

Check warning on line 95 in selfservice/strategy/oidc/provider_x.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_x.go#L95

Added line #L95 was not covered by tests
CallbackURL: p.config.Redir(p.reg.Config().OIDCRedirectURIBase(ctx)),
}
}
Expand Down
Loading