Skip to content

Commit

Permalink
feat: oidc provider epic games
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorgagu committed Jan 25, 2024
1 parent f1493c8 commit b45cfc7
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 2 deletions.
3 changes: 2 additions & 1 deletion embedx/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,8 @@
"dingtalk",
"patreon",
"linkedin",
"lark"
"lark",
"epic-games"
],
"examples": ["google"]
},
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
// - epic-games
Provider string `json:"provider"`

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

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

package oidc

import (
"context"
"net/url"

"golang.org/x/oauth2"
)

type ProviderEpicGames struct {
*ProviderGenericOIDC
}

type EpicGamesIdentityResponse struct {
Data struct {
Sub string `json:"sub"`
} `json:"data"`
}

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

Check warning on line 31 in selfservice/strategy/oidc/provider_epic_games.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_epic_games.go#L26-L31

Added lines #L26 - L31 were not covered by tests
}
}

func (e *ProviderEpicGames) Config() *Configuration {
return e.config

Check warning on line 36 in selfservice/strategy/oidc/provider_epic_games.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_epic_games.go#L35-L36

Added lines #L35 - L36 were not covered by tests
}

func (e *ProviderEpicGames) oauth2(ctx context.Context) (*oauth2.Config, error) {
return &oauth2.Config{
ClientID: e.config.ClientID,
ClientSecret: e.config.ClientSecret,
Scopes: e.config.Scope,
Endpoint: oauth2.Endpoint{
AuthURL: "https://www.epicgames.com/id/authorize",
TokenURL: "https://api.epicgames.dev/epic/oauth/v2/token",
AuthStyle: oauth2.AuthStyleInHeader,
},
RedirectURL: e.config.Redir(e.reg.Config().OIDCRedirectURIBase(ctx)),
}, nil

Check warning on line 50 in selfservice/strategy/oidc/provider_epic_games.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_epic_games.go#L39-L50

Added lines #L39 - L50 were not covered by tests
}

func (e *ProviderEpicGames) OAuth2(ctx context.Context) (*oauth2.Config, error) {
e.reg.Logger().WithField("provider", "epic-games").Trace("ProviderCreating new oauth2 configuration in OAuth2 method.")
return e.oauth2(ctx)

Check warning on line 55 in selfservice/strategy/oidc/provider_epic_games.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_epic_games.go#L53-L55

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

func (e *ProviderEpicGames) Claims(ctx context.Context, exchange *oauth2.Token, query url.Values) (*Claims, error) {
claims := &Claims{
Issuer: "https://api.epicgames.dev/epic/oauth/v2",
Subject: exchange.Extra("account_id").(string),

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

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_epic_games.go#L58-L61

Added lines #L58 - L61 were not covered by tests
}

return claims, nil

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

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_epic_games.go#L64

Added line #L64 was not covered by tests
}

func (e *ProviderEpicGames) AuthCodeURLOptions(r ider) []oauth2.AuthCodeOption {
return []oauth2.AuthCodeOption{}

Check warning on line 68 in selfservice/strategy/oidc/provider_epic_games.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/provider_epic_games.go#L67-L68

Added lines #L67 - L68 were not covered by tests
}
1 change: 1 addition & 0 deletions selfservice/strategy/oidc/provider_private_net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func TestProviderPrivateIP(t *testing.T) {
// VK uses a fixed token URL and does not use the issuer.
// Yandex uses a fixed token URL and does not use the issuer.
// NetID uses a fixed token URL and does not use the issuer.
// Epic Games uses a fixed token URL and does not use the issuer.
} {
t.Run(fmt.Sprintf("case=%d", k), func(t *testing.T) {
p := tc.p(tc.c)
Expand Down
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 @@ -207,7 +207,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, epic-games.
*/
export type Provider =
| "github"
Expand All @@ -229,6 +229,7 @@ export type Provider =
| "patreon"
| "linkedin"
| "lark"
| "epic-games"
export type OptionalStringWhichWillBeUsedWhenGeneratingLabelsForUIButtons =
string
/**
Expand Down

0 comments on commit b45cfc7

Please sign in to comment.