Skip to content

Commit

Permalink
fix(providers): profile types (#4202)
Browse files Browse the repository at this point in the history
  • Loading branch information
ubbe-xyz committed Apr 22, 2022
1 parent 9f40cd1 commit 8288ae5
Show file tree
Hide file tree
Showing 30 changed files with 130 additions and 106 deletions.
9 changes: 4 additions & 5 deletions packages/next-auth/src/providers/42-school.ts
Expand Up @@ -134,8 +134,7 @@ export interface CampusUser {
created_at: string
updated_at: string | null
}

export interface FortyTwoProfile extends UserData {
export interface FortyTwoProfile extends UserData, Record<string, any> {
groups: Array<{ id: string; name: string }>
cursus_users: CursusUser[]
projects_users: ProjectUser[]
Expand All @@ -153,9 +152,9 @@ export interface FortyTwoProfile extends UserData {
user: any | null
}

export default function FortyTwo<
P extends Record<string, any> = FortyTwoProfile
>(options: OAuthUserConfig<P>): OAuthConfig<P> {
export default function FortyTwo<P extends FortyTwoProfile>(
options: OAuthUserConfig<P>
): OAuthConfig<P> {
return {
id: "42-school",
name: "42 School",
Expand Down
4 changes: 2 additions & 2 deletions packages/next-auth/src/providers/apple.ts
Expand Up @@ -5,7 +5,7 @@ import { OAuthConfig, OAuthUserConfig } from "."
* [Retrieve the User's Information from Apple ID Servers
](https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_rest_api/authenticating_users_with_sign_in_with_apple#3383773)
*/
export interface AppleProfile {
export interface AppleProfile extends Record<string, any> {
/**
* The issuer registered claim identifies the principal that issued the identity token.
* Since Apple generates the token, the value is `https://appleid.apple.com`.
Expand Down Expand Up @@ -87,7 +87,7 @@ export interface AppleProfile {
auth_time: number
}

export default function Apple<P extends Record<string, any> = AppleProfile>(
export default function Apple<P extends AppleProfile>(
options: Omit<OAuthUserConfig<P>, "clientSecret"> & {
/**
* Apple requires the client secret to be a JWT. You can generate one using the following script:
Expand Down
2 changes: 1 addition & 1 deletion packages/next-auth/src/providers/atlassian.ts
@@ -1,6 +1,6 @@
import type { OAuthConfig, OAuthUserConfig } from "."

interface AtlassianProfile {
interface AtlassianProfile extends Record<string, any> {
account_id: string
name: string
email: string
Expand Down
4 changes: 2 additions & 2 deletions packages/next-auth/src/providers/auth0.ts
@@ -1,13 +1,13 @@
import type { OAuthConfig, OAuthUserConfig } from "."

export interface Auth0Profile {
export interface Auth0Profile extends Record<string, any> {
sub: string
nickname: string
email: string
picture: string
}

export default function Auth0<P extends Record<string, any> = Auth0Profile>(
export default function Auth0<P extends Auth0Profile>(
options: OAuthUserConfig<P>
): OAuthConfig<P> {
return {
Expand Down
42 changes: 21 additions & 21 deletions packages/next-auth/src/providers/authentik.ts
@@ -1,29 +1,29 @@
import type { OAuthConfig, OAuthUserConfig } from "."

export interface AuthentikProfile {
iss: string,
sub: string,
aud: string,
exp: number,
iat: number,
auth_time: number,
acr: string,
c_hash: string,
nonce: string,
at_hash: string,
email: string,
email_verified: boolean,
name: string,
given_name: string,
family_name: string,
preferred_username: string,
nickname: string,
export interface AuthentikProfile extends Record<string, any> {
iss: string
sub: string
aud: string
exp: number
iat: number
auth_time: number
acr: string
c_hash: string
nonce: string
at_hash: string
email: string
email_verified: boolean
name: string
given_name: string
family_name: string
preferred_username: string
nickname: string
groups: string[]
}

export default function Authentik<
P extends Record<string, any> = AuthentikProfile
>(options: OAuthUserConfig<P>): OAuthConfig<P> {
export default function Authentik<P extends AuthentikProfile>(
options: OAuthUserConfig<P>
): OAuthConfig<P> {
return {
id: "authentik",
name: "Authentik",
Expand Down
6 changes: 2 additions & 4 deletions packages/next-auth/src/providers/azure-ad-b2c.ts
@@ -1,6 +1,6 @@
import type { OAuthConfig, OAuthUserConfig } from "."

export interface AzureB2CProfile {
export interface AzureB2CProfile extends Record<string, any> {
exp: number
nbf: number
ver: string
Expand All @@ -17,9 +17,7 @@ export interface AzureB2CProfile {
tfp: string
}

export default function AzureADB2C<
P extends Record<string, any> = AzureB2CProfile
>(
export default function AzureADB2C<P extends AzureB2CProfile>(
options: OAuthUserConfig<P> & {
primaryUserFlow: string
tenantId: string
Expand Down
4 changes: 2 additions & 2 deletions packages/next-auth/src/providers/azure-ad.ts
@@ -1,13 +1,13 @@
import type { OAuthConfig, OAuthUserConfig } from "."

export interface AzureADProfile {
export interface AzureADProfile extends Record<string, any> {
sub: string
nicname: string
email: string
picture: string
}

export default function AzureAD<P extends Record<string, any> = AzureADProfile>(
export default function AzureAD<P extends AzureADProfile>(
options: OAuthUserConfig<P> & {
/**
* https://docs.microsoft.com/en-us/graph/api/profilephoto-get?view=graph-rest-1.0#examples
Expand Down
8 changes: 4 additions & 4 deletions packages/next-auth/src/providers/battlenet.ts
@@ -1,6 +1,6 @@
import type { OAuthConfig, OAuthUserConfig } from "."

export interface BattleNetProfile {
export interface BattleNetProfile extends Record<string, any> {
sub: string
battle_tag: string
}
Expand All @@ -10,9 +10,9 @@ export type BattleNetIssuer =
| "https://www.battlenet.com.cn/oauth"
| `https://${"us" | "eu" | "kr" | "tw"}.battle.net/oauth`

export default function BattleNet<
P extends Record<string, any> = BattleNetProfile
>(options: OAuthUserConfig<P> & { issuer: BattleNetIssuer }): OAuthConfig<P> {
export default function BattleNet<P extends BattleNetProfile>(
options: OAuthUserConfig<P> & { issuer: BattleNetIssuer }
): OAuthConfig<P> {
return {
id: "battlenet",
name: "Battle.net",
Expand Down
10 changes: 5 additions & 5 deletions packages/next-auth/src/providers/boxyhq-saml.ts
@@ -1,15 +1,15 @@
import type { OAuthConfig, OAuthUserConfig } from "."

export interface BoxyHQSAMLProfile {
export interface BoxyHQSAMLProfile extends Record<string, any> {
id: string
email: string
firstName?: string
lastName?: string
}

export default function SAMLJackson<
P extends Record<string, any> = BoxyHQSAMLProfile
>(options: OAuthUserConfig<P>): OAuthConfig<P> {
export default function SAMLJackson<P extends BoxyHQSAMLProfile>(
options: OAuthUserConfig<P>
): OAuthConfig<P> {
return {
id: "boxyhq-saml",
name: "BoxyHQ SAML",
Expand All @@ -34,4 +34,4 @@ export default function SAMLJackson<
},
options,
}
}
}
4 changes: 2 additions & 2 deletions packages/next-auth/src/providers/cognito.ts
@@ -1,13 +1,13 @@
import type { OAuthConfig, OAuthUserConfig } from "."

export interface CognitoProfile {
export interface CognitoProfile extends Record<string, any> {
sub: string
name: string
email: string
picture: string
}

export default function Cognito<P extends Record<string, any> = CognitoProfile>(
export default function Cognito<P extends CognitoProfile>(
options: OAuthUserConfig<P>
): OAuthConfig<P> {
return {
Expand Down
@@ -1,5 +1,26 @@
/** @type {import(".").OAuthProvider} */
export default function Discord(options) {
import type { OAuthConfig, OAuthUserConfig } from "."

export interface DiscordProfile extends Record<string, any> {
accent_color: number
avatar: string
banner: string
banner_color: string
discriminator: string
email: string
flags: number
id: string
image_url: string
locale: string
mfa_enabled: boolean
premium_type: number
public_flags: number
username: string
verified: boolean
}

export default function Discord<P extends DiscordProfile>(
options: OAuthUserConfig<P>
): OAuthConfig<P> {
return {
id: "discord",
name: "Discord",
Expand Down
10 changes: 5 additions & 5 deletions packages/next-auth/src/providers/eveonline.ts
@@ -1,6 +1,6 @@
import type { OAuthConfig, OAuthUserConfig } from "."

export interface EVEOnlineProfile {
export interface EVEOnlineProfile extends Record<string, any> {
CharacterID: number
CharacterName: string
ExpiresOn: string
Expand All @@ -10,9 +10,9 @@ export interface EVEOnlineProfile {
IntellectualProperty: string
}

export default function EVEOnline<
P extends Record<string, any> = EVEOnlineProfile
>(options: OAuthUserConfig<P>): OAuthConfig<P> {
export default function EVEOnline<P extends EVEOnlineProfile>(
options: OAuthUserConfig<P>
): OAuthConfig<P> {
return {
id: "eveonline",
name: "EVE Online",
Expand All @@ -27,7 +27,7 @@ export default function EVEOnline<
idToken: true,
profile(profile) {
return {
id: profile.CharacterID,
id: String(profile.CharacterID),
name: profile.CharacterName,
email: null,
image: `https://image.eveonline.com/Character/${profile.CharacterID}_128.jpg`,
Expand Down
17 changes: 12 additions & 5 deletions packages/next-auth/src/providers/facebook.ts
@@ -1,13 +1,20 @@
import type { OAuthConfig, OAuthUserConfig } from "."

export interface FacebookProfile {
interface FacebookPictureData {
url: string
}

interface FacebookPicture {
data: FacebookPictureData
}
export interface FacebookProfile extends Record<string, any> {
id: string
picture: { data: { url: string } }
picture: FacebookPicture
}

export default function Facebook<
P extends Record<string, any> = FacebookProfile
>(options: OAuthUserConfig<P>): OAuthConfig<P> {
export default function Facebook<P extends FacebookProfile>(
options: OAuthUserConfig<P>
): OAuthConfig<P> {
return {
id: "facebook",
name: "Facebook",
Expand Down
6 changes: 2 additions & 4 deletions packages/next-auth/src/providers/fusionauth.ts
Expand Up @@ -3,7 +3,7 @@ import { OAuthConfig, OAuthUserConfig } from "./oauth"
/** This is the default openid signature returned from FusionAuth
* it can be customized using [lambda functions](https://fusionauth.io/docs/v1/tech/lambdas)
*/
export interface FusionAuthProfile {
export interface FusionAuthProfile extends Record<string, any> {
aud: string
exp: number
iat: number
Expand All @@ -20,9 +20,7 @@ export interface FusionAuthProfile {
sid: string
}

export default function FusionAuth<
P extends Record<string, any> = FusionAuthProfile
>(
export default function FusionAuth<P extends FusionAuthProfile>(
// tenantId only needed if there is more than one tenant configured on the server
options: OAuthUserConfig<P> & { tenantId?: string }
): OAuthConfig<P> {
Expand Down
4 changes: 2 additions & 2 deletions packages/next-auth/src/providers/google.ts
@@ -1,6 +1,6 @@
import type { OAuthConfig, OAuthUserConfig } from "."

export interface GoogleProfile {
export interface GoogleProfile extends Record<string, any> {
aud: string
azp: string
email: string
Expand All @@ -18,7 +18,7 @@ export interface GoogleProfile {
sub: string
}

export default function Google<P extends Record<string, any> = GoogleProfile>(
export default function Google<P extends GoogleProfile>(
options: OAuthUserConfig<P>
): OAuthConfig<P> {
return {
Expand Down
6 changes: 3 additions & 3 deletions packages/next-auth/src/providers/kakao.ts
Expand Up @@ -19,7 +19,7 @@ export type AgeRange =
* https://developers.kakao.com/docs/latest/ko/kakaologin/rest-api#req-user-info
* type from : https://gist.github.com/ziponia/cdce1ebd88f979b2a6f3f53416b56a77
*/
export interface KakaoProfile {
export interface KakaoProfile extends Record<string, any> {
id: number
has_signed_up?: boolean
connected_at?: DateTime
Expand Down Expand Up @@ -66,7 +66,7 @@ export interface KakaoProfile {
}
}

export default function Kakao<P extends Record<string, any> = KakaoProfile>(
export default function Kakao<P extends KakaoProfile>(
options: OAuthUserConfig<P>
): OAuthConfig<P> {
return {
Expand All @@ -81,7 +81,7 @@ export default function Kakao<P extends Record<string, any> = KakaoProfile>(
},
profile(profile) {
return {
id: profile.id,
id: String(profile.id),
name: profile.kakao_account?.profile?.nickname,
email: profile.kakao_account?.email,
image: profile.kakao_account?.profile?.profile_image_url,
Expand Down
8 changes: 4 additions & 4 deletions packages/next-auth/src/providers/keycloak.ts
@@ -1,6 +1,6 @@
import type { OAuthConfig, OAuthUserConfig } from "."

export interface KeycloakProfile {
export interface KeycloakProfile extends Record<string, any> {
exp: number
iat: number
auth_time: number
Expand All @@ -24,9 +24,9 @@ export interface KeycloakProfile {
user: any
}

export default function Keycloak<
P extends Record<string, any> = KeycloakProfile
>(options: OAuthUserConfig<P>): OAuthConfig<P> {
export default function Keycloak<P extends KeycloakProfile>(
options: OAuthUserConfig<P>
): OAuthConfig<P> {
return {
id: "keycloak",
name: "Keycloak",
Expand Down

0 comments on commit 8288ae5

Please sign in to comment.