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: update Yandex and VK OIDC #4158

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 selfservice/strategy/oidc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Provider interface {
type OAuth2Provider interface {
Provider
AuthCodeURLOptions(r ider) []oauth2.AuthCodeOption
AccessTokenURLOptions(r *http.Request) []oauth2.AuthCodeOption
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this method is only relevant for VK, we could also extract it into a separate interface that only the VK provider implements. Then, in strategy.go we assert on the interface and add the options if the provider implements it.

That way, we don't have to give empty implementations to every other provider. WDYT?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add a new interface, but I need some directions. How to name this new interface?
I used the same interface because AuthCodeURLOptions isn't in a separate interface either (there's empty implementations for this method too).

OAuth2(ctx context.Context) (*oauth2.Config, error)
Claims(ctx context.Context, exchange *oauth2.Token, query url.Values) (*Claims, error)
}
Expand Down
6 changes: 4 additions & 2 deletions selfservice/strategy/oidc/provider_apple.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"golang.org/x/oauth2"
)

var _ OAuth2Provider = (*ProviderApple)(nil)

type ProviderApple struct {
*ProviderGenericOIDC
JWKSUrl string
Expand Down Expand Up @@ -152,7 +154,7 @@ func (a *ProviderApple) DecodeQuery(query url.Values, claims *Claims) {
}
}

var _ IDTokenVerifier = new(ProviderApple)
var _ IDTokenVerifier = (*ProviderApple)(nil)

const issuerUrlApple = "https://appleid.apple.com"

Expand All @@ -163,7 +165,7 @@ func (a *ProviderApple) Verify(ctx context.Context, rawIDToken string) (*Claims,
return verifyToken(ctx, keySet, a.config, rawIDToken, issuerUrlApple)
}

var _ NonceValidationSkipper = new(ProviderApple)
var _ NonceValidationSkipper = (*ProviderApple)(nil)

func (a *ProviderApple) CanSkipNonce(c *Claims) bool {
return c.NonceSupported
Expand Down
2 changes: 2 additions & 0 deletions selfservice/strategy/oidc/provider_auth0.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"github.com/ory/herodot"
)

var _ OAuth2Provider = (*ProviderAuth0)(nil)

type ProviderAuth0 struct {
*ProviderGenericOIDC
}
Expand Down
7 changes: 7 additions & 0 deletions selfservice/strategy/oidc/provider_dingtalk.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package oidc
import (
"context"
"encoding/json"
"net/http"
"net/url"
"strings"
"time"
Expand All @@ -20,6 +21,8 @@ import (
"github.com/ory/herodot"
)

var _ OAuth2Provider = (*ProviderDingTalk)(nil)

type ProviderDingTalk struct {
config *Configuration
reg Dependencies
Expand Down Expand Up @@ -61,6 +64,10 @@ func (g *ProviderDingTalk) AuthCodeURLOptions(r ider) []oauth2.AuthCodeOption {
}
}

func (g *ProviderDingTalk) AccessTokenURLOptions(r *http.Request) []oauth2.AuthCodeOption {
return []oauth2.AuthCodeOption{}
}

func (g *ProviderDingTalk) OAuth2(ctx context.Context) (*oauth2.Config, error) {
return g.oauth2(ctx), nil
}
Expand Down
7 changes: 7 additions & 0 deletions selfservice/strategy/oidc/provider_discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package oidc
import (
"context"
"fmt"
"net/http"
"net/url"

"github.com/ory/kratos/x"
Expand All @@ -19,6 +20,8 @@ import (
"github.com/ory/x/stringsx"
)

var _ OAuth2Provider = (*ProviderDiscord)(nil)

type ProviderDiscord struct {
config *Configuration
reg Dependencies
Expand Down Expand Up @@ -66,6 +69,10 @@ func (d *ProviderDiscord) AuthCodeURLOptions(r ider) []oauth2.AuthCodeOption {
}
}

func (g *ProviderDiscord) AccessTokenURLOptions(r *http.Request) []oauth2.AuthCodeOption {
return []oauth2.AuthCodeOption{}
}

func (d *ProviderDiscord) Claims(ctx context.Context, exchange *oauth2.Token, query url.Values) (*Claims, error) {
grantedScopes := stringsx.Splitx(fmt.Sprintf("%s", exchange.Extra("scope")), " ")
for _, check := range d.Config().Scope {
Expand Down
2 changes: 2 additions & 0 deletions selfservice/strategy/oidc/provider_facebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/ory/herodot"
)

var _ OAuth2Provider = (*ProviderFacebook)(nil)

type ProviderFacebook struct {
*ProviderGenericOIDC
}
Expand Down
8 changes: 7 additions & 1 deletion selfservice/strategy/oidc/provider_generic_oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package oidc

import (
"context"
"net/http"
"net/url"

"github.com/pkg/errors"
Expand All @@ -16,7 +17,8 @@ import (
"github.com/ory/x/stringslice"
)

var _ Provider = new(ProviderGenericOIDC)
var _ Provider = (*ProviderGenericOIDC)(nil)
var _ OAuth2Provider = (*ProviderGenericOIDC)(nil)

type ProviderGenericOIDC struct {
p *gooidc.Provider
Expand Down Expand Up @@ -96,6 +98,10 @@ func (g *ProviderGenericOIDC) AuthCodeURLOptions(r ider) []oauth2.AuthCodeOption
return options
}

func (g *ProviderGenericOIDC) AccessTokenURLOptions(r *http.Request) []oauth2.AuthCodeOption {
return []oauth2.AuthCodeOption{}
}

func (g *ProviderGenericOIDC) verifyAndDecodeClaimsWithProvider(ctx context.Context, provider *gooidc.Provider, raw string) (*Claims, error) {
token, err := provider.VerifierContext(g.withHTTPClientContext(ctx), &gooidc.Config{ClientID: g.config.ClientID}).Verify(ctx, raw)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions selfservice/strategy/oidc/provider_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package oidc
import (
"context"
"fmt"
"net/http"
"net/url"

"github.com/ory/kratos/x"
Expand All @@ -23,6 +24,8 @@ import (
"github.com/ory/herodot"
)

var _ OAuth2Provider = (*ProviderGitHub)(nil)

type ProviderGitHub struct {
config *Configuration
reg Dependencies
Expand Down Expand Up @@ -60,6 +63,10 @@ func (g *ProviderGitHub) AuthCodeURLOptions(r ider) []oauth2.AuthCodeOption {
return []oauth2.AuthCodeOption{}
}

func (g *ProviderGitHub) AccessTokenURLOptions(r *http.Request) []oauth2.AuthCodeOption {
return []oauth2.AuthCodeOption{}
}

func (g *ProviderGitHub) Claims(ctx context.Context, exchange *oauth2.Token, query url.Values) (*Claims, error) {
grantedScopes := stringsx.Splitx(fmt.Sprintf("%s", exchange.Extra("scope")), ",")
for _, check := range g.Config().Scope {
Expand Down
7 changes: 7 additions & 0 deletions selfservice/strategy/oidc/provider_github_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package oidc
import (
"context"
"fmt"
"net/http"
"net/url"

"github.com/ory/kratos/x"
Expand All @@ -20,6 +21,8 @@ import (
"github.com/ory/herodot"
)

var _ OAuth2Provider = (*ProviderGitHubApp)(nil)

type ProviderGitHubApp struct {
config *Configuration
reg Dependencies
Expand Down Expand Up @@ -57,6 +60,10 @@ func (g *ProviderGitHubApp) AuthCodeURLOptions(r ider) []oauth2.AuthCodeOption {
return []oauth2.AuthCodeOption{}
}

func (g *ProviderGitHubApp) AccessTokenURLOptions(r *http.Request) []oauth2.AuthCodeOption {
return []oauth2.AuthCodeOption{}
}

func (g *ProviderGitHubApp) Claims(ctx context.Context, exchange *oauth2.Token, query url.Values) (*Claims, error) {
ctx, client := httpx.SetOAuth2(ctx, g.reg.HTTPClient(ctx), g.oauth2(ctx), exchange)
gh := ghapi.NewClient(client.HTTPClient)
Expand Down
2 changes: 2 additions & 0 deletions selfservice/strategy/oidc/provider_gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const (
defaultEndpoint = "https://gitlab.com"
)

var _ OAuth2Provider = (*ProviderGitLab)(nil)

type ProviderGitLab struct {
*ProviderGenericOIDC
}
Expand Down
6 changes: 4 additions & 2 deletions selfservice/strategy/oidc/provider_google.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/ory/x/stringslice"
)

var _ OAuth2Provider = (*ProviderGoogle)(nil)

type ProviderGoogle struct {
*ProviderGenericOIDC
JWKSUrl string
Expand Down Expand Up @@ -69,7 +71,7 @@ func (g *ProviderGoogle) AuthCodeURLOptions(r ider) []oauth2.AuthCodeOption {
return options
}

var _ IDTokenVerifier = new(ProviderGoogle)
var _ IDTokenVerifier = (*ProviderGoogle)(nil)

const issuerUrlGoogle = "https://accounts.google.com"

Expand All @@ -79,7 +81,7 @@ func (p *ProviderGoogle) Verify(ctx context.Context, rawIDToken string) (*Claims
return verifyToken(ctx, keySet, p.config, rawIDToken, issuerUrlGoogle)
}

var _ NonceValidationSkipper = new(ProviderGoogle)
var _ NonceValidationSkipper = (*ProviderGoogle)(nil)

func (a *ProviderGoogle) CanSkipNonce(c *Claims) bool {
// Not all SDKs support nonce validation, so we skip it if no nonce is present in the claims of the ID Token.
Expand Down
2 changes: 2 additions & 0 deletions selfservice/strategy/oidc/provider_lark.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/ory/x/httpx"
)

var _ OAuth2Provider = (*ProviderLark)(nil)

type ProviderLark struct {
*ProviderGenericOIDC
}
Expand Down
6 changes: 6 additions & 0 deletions selfservice/strategy/oidc/provider_linkedin.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ const (
IntrospectionURL string = "https://www.linkedin.com/oauth/v2/introspectToken"
)

var _ OAuth2Provider = (*ProviderLinkedIn)(nil)

type ProviderLinkedIn struct {
config *Configuration
reg Dependencies
Expand Down Expand Up @@ -100,6 +102,10 @@ func (l *ProviderLinkedIn) AuthCodeURLOptions(r ider) []oauth2.AuthCodeOption {
return []oauth2.AuthCodeOption{}
}

func (g *ProviderLinkedIn) AccessTokenURLOptions(r *http.Request) []oauth2.AuthCodeOption {
return []oauth2.AuthCodeOption{}
}

func (l *ProviderLinkedIn) fetch(ctx context.Context, client *retryablehttp.Client, url string, result interface{}) (err error) {
ctx, span := l.reg.Tracer(ctx).Tracer().Start(ctx, "selfservice.strategy.oidc.ProviderLinkedIn.fetch")
defer otelx.End(span, &err)
Expand Down
2 changes: 2 additions & 0 deletions selfservice/strategy/oidc/provider_microsoft.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"github.com/ory/herodot"
)

var _ OAuth2Provider = (*ProviderMicrosoft)(nil)

type ProviderMicrosoft struct {
*ProviderGenericOIDC
}
Expand Down
2 changes: 2 additions & 0 deletions selfservice/strategy/oidc/provider_netid.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const (
defaultBrokerHost = "broker.netid.de"
)

var _ OAuth2Provider = (*ProviderNetID)(nil)

type ProviderNetID struct {
*ProviderGenericOIDC
}
Expand Down
7 changes: 7 additions & 0 deletions selfservice/strategy/oidc/provider_patreon.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package oidc
import (
"context"
"encoding/json"
"net/http"
"net/url"

"github.com/hashicorp/go-retryablehttp"
Expand All @@ -18,6 +19,8 @@ import (
"github.com/ory/herodot"
)

var _ OAuth2Provider = (*ProviderPatreon)(nil)

type ProviderPatreon struct {
config *Configuration
reg Dependencies
Expand Down Expand Up @@ -79,6 +82,10 @@ func (d *ProviderPatreon) AuthCodeURLOptions(r ider) []oauth2.AuthCodeOption {
}
}

func (g *ProviderPatreon) AccessTokenURLOptions(r *http.Request) []oauth2.AuthCodeOption {
return []oauth2.AuthCodeOption{}
}

func (d *ProviderPatreon) Claims(ctx context.Context, exchange *oauth2.Token, query url.Values) (*Claims, error) {
identityUrl := "https://www.patreon.com/api/oauth2/v2/identity?fields%5Buser%5D=first_name,last_name,url,full_name,email,image_url"

Expand Down
2 changes: 2 additions & 0 deletions selfservice/strategy/oidc/provider_salesforce.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"github.com/ory/herodot"
)

var _ OAuth2Provider = (*ProviderSalesforce)(nil)

type ProviderSalesforce struct {
*ProviderGenericOIDC
}
Expand Down
7 changes: 7 additions & 0 deletions selfservice/strategy/oidc/provider_slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package oidc
import (
"context"
"fmt"
"net/http"
"net/url"

"github.com/ory/herodot"
Expand All @@ -19,6 +20,8 @@ import (
"github.com/slack-go/slack"
)

var _ OAuth2Provider = (*ProviderSlack)(nil)

type ProviderSlack struct {
config *Configuration
reg Dependencies
Expand Down Expand Up @@ -61,6 +64,10 @@ func (d *ProviderSlack) AuthCodeURLOptions(r ider) []oauth2.AuthCodeOption {
return []oauth2.AuthCodeOption{}
}

func (g *ProviderSlack) AccessTokenURLOptions(r *http.Request) []oauth2.AuthCodeOption {
return []oauth2.AuthCodeOption{}
}

func (d *ProviderSlack) Claims(ctx context.Context, exchange *oauth2.Token, query url.Values) (*Claims, error) {
grantedScopes := stringsx.Splitx(fmt.Sprintf("%s", exchange.Extra("scope")), ",")
for _, check := range d.Config().Scope {
Expand Down
7 changes: 7 additions & 0 deletions selfservice/strategy/oidc/provider_spotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package oidc
import (
"context"
"fmt"
"net/http"
"net/url"

"golang.org/x/oauth2/spotify"
Expand All @@ -23,6 +24,8 @@ import (
"github.com/ory/herodot"
)

var _ OAuth2Provider = (*ProviderSpotify)(nil)

type ProviderSpotify struct {
config *Configuration
reg Dependencies
Expand Down Expand Up @@ -60,6 +63,10 @@ func (g *ProviderSpotify) AuthCodeURLOptions(r ider) []oauth2.AuthCodeOption {
return []oauth2.AuthCodeOption{}
}

func (g *ProviderSpotify) AccessTokenURLOptions(r *http.Request) []oauth2.AuthCodeOption {
return []oauth2.AuthCodeOption{}
}

func (g *ProviderSpotify) Claims(ctx context.Context, exchange *oauth2.Token, query url.Values) (*Claims, error) {
grantedScopes := stringsx.Splitx(fmt.Sprintf("%s", exchange.Extra("scope")), " ")
for _, check := range g.Config().Scope {
Expand Down
Loading
Loading