Skip to content

Commit

Permalink
Merge 7254d3e into afed81d
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlmo committed Oct 19, 2023
2 parents afed81d + 7254d3e commit 8e19e6f
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 15 deletions.
29 changes: 15 additions & 14 deletions embedx/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -410,28 +410,29 @@
},
"provider": {
"title": "Provider",
"description": "Can be one of github, github-app, gitlab, generic, google, microsoft, discord, slack, facebook, auth0, vk, yandex, apple, spotify, netid, dingtalk, patreon.",
"description": "Can be one of apple, auth0, dingtalk, discord, facebook, generic, github-app, github, gitlab, google, lark, linkedin, microsoft, netid, patreon, signicat, slack, spotify, vk, yandex",
"type": "string",
"enum": [
"github",
"apple",
"auth0",
"dingtalk",
"discord",
"facebook",
"generic",
"github-app",
"github",
"gitlab",
"generic",
"google",
"lark",
"linkedin",
"microsoft",
"discord",
"slack",
"facebook",
"auth0",
"vk",
"yandex",
"apple",
"spotify",
"netid",
"dingtalk",
"patreon",
"linkedin",
"lark"
"signicat",
"slack",
"spotify",
"vk",
"yandex"
],
"examples": ["google"]
},
Expand Down
3 changes: 3 additions & 0 deletions selfservice/strategy/oidc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ type Claims struct {
Name string `json:"name,omitempty"`
GivenName string `json:"given_name,omitempty"`
FamilyName string `json:"family_name,omitempty"`
IdpId string `json:"idp_id,omitempty"`
IdpSub string `json:"idp_sub,omitempty"`
Nin string `json:"nin,omitempty"`
LastName string `json:"last_name,omitempty"`
MiddleName string `json:"middle_name,omitempty"`
Nickname string `json:"nickname,omitempty"`
Expand Down
2 changes: 2 additions & 0 deletions selfservice/strategy/oidc/provider_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Configuration struct {
// - dingtalk
// - linkedin
// - patreon
// - signicat
Provider string `json:"provider"`

// Label represents an optional label which can be used in the UI generation.
Expand Down Expand Up @@ -150,6 +151,7 @@ var supportedProviders = map[string]func(config *Configuration, reg Dependencies
"linkedin": NewProviderLinkedIn,
"patreon": NewProviderPatreon,
"lark": NewProviderLark,
"signicat": NewProviderSignicat,
}

func (c ConfigurationCollection) Provider(id string, reg Dependencies) (Provider, error) {
Expand Down
130 changes: 130 additions & 0 deletions selfservice/strategy/oidc/provider_signicat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0

package oidc

import (
"context"
"encoding/json"
"net/http"
"net/url"
"path"

"github.com/ory/x/stringsx"

"github.com/hashicorp/go-retryablehttp"

"github.com/ory/x/httpx"

"github.com/pkg/errors"
"golang.org/x/oauth2"

"github.com/ory/herodot"
)

const (
signicatBaseUrl = "https://client.sandbox.signicat.com"
)

type ProviderSignicat struct {
*ProviderGenericOIDC
}

type UserInfoResponse struct {
IdpId string `json:"idp_id,omitempty"`
FamilyName string `json:"family_name,omitempty"`
GivenName string `json:"given_name,omitempty"`
Birthdate string `json:"birthdate,omitempty"`
Nin string `json:"nin,omitempty"`
NinType string `json:"nin_type,omitempty"`
NinIssuingCountry string `json:"nin_issuing_country,omitempty"`
Sub string `json:"sub,omitempty"`
SubLegacy string `json:"sub_legacy,omitempty"`
}

func NewProviderSignicat(
config *Configuration,
reg Dependencies,
) Provider {
return &ProviderSignicat{
ProviderGenericOIDC: &ProviderGenericOIDC{
config: config,
reg: reg,
},

Check warning on line 53 in selfservice/strategy/oidc/provider_signicat.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_signicat.go#L48-L53

Added lines #L48 - L53 were not covered by tests
}
}

func (g *ProviderSignicat) oauth2(ctx context.Context) (*oauth2.Config, error) {
endpoint, err := g.endpoint()
if err != nil {
return nil, errors.WithStack(herodot.ErrInternalServerError.WithReasonf("%s", err))

Check warning on line 60 in selfservice/strategy/oidc/provider_signicat.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_signicat.go#L57-L60

Added lines #L57 - L60 were not covered by tests
}

authUrl := *endpoint
tokenUrl := *endpoint

Check warning on line 64 in selfservice/strategy/oidc/provider_signicat.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_signicat.go#L63-L64

Added lines #L63 - L64 were not covered by tests

authUrl.Path = path.Join(authUrl.Path, "/connect/authorize")
tokenUrl.Path = path.Join(tokenUrl.Path, "/connect/token")

Check warning on line 67 in selfservice/strategy/oidc/provider_signicat.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_signicat.go#L66-L67

Added lines #L66 - L67 were not covered by tests

return &oauth2.Config{
ClientID: g.config.ClientID,
ClientSecret: g.config.ClientSecret,
Endpoint: oauth2.Endpoint{
AuthURL: authUrl.String(),
TokenURL: tokenUrl.String(),
},
Scopes: g.config.Scope,
RedirectURL: g.config.Redir(g.reg.Config().OIDCRedirectURIBase(ctx)),
}, nil

Check warning on line 78 in selfservice/strategy/oidc/provider_signicat.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_signicat.go#L69-L78

Added lines #L69 - L78 were not covered by tests
}

func (g *ProviderSignicat) OAuth2(ctx context.Context) (*oauth2.Config, error) {
return g.oauth2(ctx)

Check warning on line 82 in selfservice/strategy/oidc/provider_signicat.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_signicat.go#L81-L82

Added lines #L81 - L82 were not covered by tests
}

func (g *ProviderSignicat) Claims(ctx context.Context, exchange *oauth2.Token, query url.Values) (*Claims, error) {
o, err := g.OAuth2(ctx)
if err != nil {
return nil, errors.WithStack(herodot.ErrInternalServerError.WithReasonf("%s", err))

Check warning on line 88 in selfservice/strategy/oidc/provider_signicat.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_signicat.go#L85-L88

Added lines #L85 - L88 were not covered by tests
}

client := g.reg.HTTPClient(ctx, httpx.ResilientClientDisallowInternalIPs(), httpx.ResilientClientWithClient(o.Client(ctx, exchange)))

Check warning on line 91 in selfservice/strategy/oidc/provider_signicat.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_signicat.go#L91

Added line #L91 was not covered by tests

u, err := g.endpoint()
if err != nil {
return nil, errors.WithStack(herodot.ErrInternalServerError.WithReasonf("%s", err))

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

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_signicat.go#L93-L95

Added lines #L93 - L95 were not covered by tests
}
u.Path = path.Join(u.Path, "/connect/userinfo")
req, err := retryablehttp.NewRequest("GET", u.String(), nil)
if err != nil {
return nil, errors.WithStack(herodot.ErrInternalServerError.WithReasonf("%s", err))

Check warning on line 100 in selfservice/strategy/oidc/provider_signicat.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_signicat.go#L97-L100

Added lines #L97 - L100 were not covered by tests
}

req.Header.Set("Accept", "application/json")
resp, err := client.Do(req)
if err != nil {
return nil, errors.WithStack(herodot.ErrInternalServerError.WithReasonf("%s", err))

Check warning on line 106 in selfservice/strategy/oidc/provider_signicat.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_signicat.go#L103-L106

Added lines #L103 - L106 were not covered by tests
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, errors.WithStack(herodot.ErrInternalServerError.WithReasonf("Expected the Signicat userinfo endpoint to return a 200 OK response but got %d instead", resp.StatusCode))

Check warning on line 110 in selfservice/strategy/oidc/provider_signicat.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_signicat.go#L108-L110

Added lines #L108 - L110 were not covered by tests
}

var claims Claims

Check warning on line 113 in selfservice/strategy/oidc/provider_signicat.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_signicat.go#L113

Added line #L113 was not covered by tests

if err := json.NewDecoder(resp.Body).Decode(&claims); err != nil {
return nil, errors.WithStack(herodot.ErrInternalServerError.WithReasonf("%s", err)) // FAILS!

Check warning on line 116 in selfservice/strategy/oidc/provider_signicat.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_signicat.go#L115-L116

Added lines #L115 - L116 were not covered by tests
}

claims.Issuer = stringsx.Coalesce(claims.Issuer, g.config.IssuerURL)

Check warning on line 119 in selfservice/strategy/oidc/provider_signicat.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_signicat.go#L119

Added line #L119 was not covered by tests

return &claims, nil

Check warning on line 121 in selfservice/strategy/oidc/provider_signicat.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_signicat.go#L121

Added line #L121 was not covered by tests
}

func (g *ProviderSignicat) endpoint() (*url.URL, error) {
var e = signicatBaseUrl
if len(g.config.IssuerURL) > 0 {
e = g.config.IssuerURL

Check warning on line 127 in selfservice/strategy/oidc/provider_signicat.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_signicat.go#L124-L127

Added lines #L124 - L127 were not covered by tests
}
return url.Parse(e)

Check warning on line 129 in selfservice/strategy/oidc/provider_signicat.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_signicat.go#L129

Added line #L129 was not covered by tests
}
3 changes: 2 additions & 1 deletion test/e2e/cypress/support/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export type SelfServiceOIDCProvider1 = {
[k: string]: unknown | undefined
}
/**
* Can be one of github, github-app, gitlab, generic, google, microsoft, discord, slack, facebook, auth0, vk, yandex, apple, spotify, netid, dingtalk, patreon.
* Can be one of github, github-app, gitlab, generic, google, microsoft, discord, slack, facebook, auth0, vk, yandex, apple, spotify, netid, dingtalk, patreon, signicat.
*/
export type Provider =
| "github"
Expand All @@ -213,6 +213,7 @@ export type Provider =
| "patreon"
| "linkedin"
| "lark"
| "signicat"
export type OptionalStringWhichWillBeUsedWhenGeneratingLabelsForUIButtons =
string
/**
Expand Down

0 comments on commit 8e19e6f

Please sign in to comment.