-
Notifications
You must be signed in to change notification settings - Fork 970
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add linkedin-v2 provider * docs: document linkedin special-case
- Loading branch information
Showing
16 changed files
with
220 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -436,6 +436,7 @@ | |
"dingtalk", | ||
"patreon", | ||
"linkedin", | ||
"linkedin_v2", | ||
"lark", | ||
"x" | ||
], | ||
|
1 change: 1 addition & 0 deletions
1
...ties_with_credentials-include_credential=oidc_should_include_OIDC_credentials_config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"{\"providers\":[{\"initial_id_token\":\"id_token0\",\"initial_access_token\":\"access_token0\",\"initial_refresh_token\":\"refresh_token0\",\"subject\":\"foo\",\"provider\":\"bar\",\"organization\":\"\"},{\"initial_id_token\":\"id_token1\",\"initial_access_token\":\"access_token1\",\"initial_refresh_token\":\"refresh_token1\",\"subject\":\"baz\",\"provider\":\"zab\",\"organization\":\"\"}]}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1348,11 +1348,15 @@ func TestHandler(t *testing.T) { | |
}) | ||
|
||
t.Run("case=should list all identities with credentials", func(t *testing.T) { | ||
res := get(t, adminTS, "/identities?include_credential=totp", http.StatusOK) | ||
assert.True(t, res.Get("0.credentials").Exists(), "credentials config should be included: %s", res.Raw) | ||
assert.True(t, res.Get("0.metadata_public").Exists(), "metadata_public config should be included: %s", res.Raw) | ||
assert.True(t, res.Get("0.metadata_admin").Exists(), "metadata_admin config should be included: %s", res.Raw) | ||
assert.EqualValues(t, "baz", res.Get(`#(traits.bar=="baz").traits.bar`).String(), "%s", res.Raw) | ||
t.Run("include_credential=oidc should include OIDC credentials config", func(t *testing.T) { | ||
res := get(t, adminTS, "/identities?include_credential=oidc&credentials_identifier=bar:[email protected]", http.StatusOK) | ||
assert.True(t, res.Get("0.credentials.oidc.config").Exists(), "credentials config should be included: %s", res.Raw) | ||
snapshotx.SnapshotT(t, res.Get("0.credentials.oidc.config").String()) | ||
}) | ||
t.Run("include_credential=totp should not include OIDC credentials config", func(t *testing.T) { | ||
res := get(t, adminTS, "/identities?include_credential=totp&credentials_identifier=bar:[email protected]", http.StatusOK) | ||
assert.False(t, res.Get("0.credentials.oidc.config").Exists(), "credentials config should be included: %s", res.Raw) | ||
}) | ||
}) | ||
|
||
t.Run("case=should not be able to list all identities with credentials due to wrong credentials type", func(t *testing.T) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright © 2023 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package oidc | ||
|
||
import ( | ||
"context" | ||
"net/url" | ||
|
||
gooidc "github.com/coreos/go-oidc/v3/oidc" | ||
"golang.org/x/oauth2" | ||
) | ||
|
||
type ProviderLinkedInV2 struct { | ||
*ProviderGenericOIDC | ||
} | ||
|
||
func NewProviderLinkedInV2( | ||
config *Configuration, | ||
reg Dependencies, | ||
) Provider { | ||
config.ClaimsSource = ClaimsSourceUserInfo | ||
config.IssuerURL = "https://www.linkedin.com/oauth" | ||
|
||
return &ProviderLinkedInV2{ | ||
ProviderGenericOIDC: &ProviderGenericOIDC{ | ||
config: config, | ||
reg: reg, | ||
}, | ||
} | ||
} | ||
|
||
func (l *ProviderLinkedInV2) wrapCtx(ctx context.Context) context.Context { | ||
// We need to overwrite the issuer here because the discovery URL is under | ||
// `https://www.linkedin.com/oauth/.well-known/openid-configuration`, wherease | ||
// the issuer is `https://www.linkedin.com` (without the `/oauth`). This is | ||
// not conformant according to the OIDC spec, but needed for LinkedIn. | ||
return gooidc.InsecureIssuerURLContext(ctx, "https://www.linkedin.com") | ||
} | ||
|
||
func (l *ProviderLinkedInV2) OAuth2(ctx context.Context) (*oauth2.Config, error) { | ||
return l.ProviderGenericOIDC.OAuth2(l.wrapCtx(ctx)) | ||
} | ||
|
||
func (l *ProviderLinkedInV2) Claims(ctx context.Context, exchange *oauth2.Token, query url.Values) (*Claims, error) { | ||
return l.ProviderGenericOIDC.Claims(l.wrapCtx(ctx), exchange, query) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright © 2023 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package oidc_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/ory/kratos/internal" | ||
"github.com/ory/kratos/selfservice/strategy/oidc" | ||
) | ||
|
||
func TestProviderLinkedInV2_Discovery(t *testing.T) { | ||
_, reg := internal.NewVeryFastRegistryWithoutDB(t) | ||
|
||
p := oidc.NewProviderLinkedInV2(&oidc.Configuration{ | ||
Provider: "linkedin_v2", | ||
ID: "valid", | ||
ClientID: "client", | ||
ClientSecret: "secret", | ||
Mapper: "file://./stub/hydra.schema.json", | ||
RequestedClaims: nil, | ||
Scope: []string{"email", "profile", "offline_access"}, | ||
}, reg) | ||
|
||
c, err := p.(oidc.OAuth2Provider).OAuth2(context.Background()) | ||
require.NoError(t, err) | ||
assert.Contains(t, c.Scopes, "openid") | ||
assert.Equal(t, "https://www.linkedin.com/oauth/v2/accessToken", c.Endpoint.TokenURL) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.