Skip to content

Commit

Permalink
docs: add Auth0 and GitHub header
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsorban44 committed Jan 9, 2023
1 parent d142252 commit c05951f
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 7 deletions.
61 changes: 61 additions & 0 deletions packages/core/src/providers/auth0.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,73 @@
/**
* <div style={{backgroundColor: "#EB5424", display: "flex", justifyContent: "space-between", color: "#fff", padding: 16}}>
* <span>Built-in <b>Auth0</b> integration.</span>
* <a href="https://auth0.com">
* <img style={{display: "block"}} src="https://authjs.dev/img/providers/auth0-dark.svg" height="48" width="48"/>
* </a>
* </div>
*
* ---
* @module providers/auth0
*/

import type { OAuthConfig, OAuthUserConfig } from "./index.js"

/** @see [User Profile Structure](https://auth0.com/docs/manage-users/user-accounts/user-profiles/user-profile-structure) */
export interface Auth0Profile extends Record<string, any> {
sub: string
nickname: string
email: string
picture: string
}

/**
* Add Auth0 login to your page.
*
* ## Example
*
* @example
*
* ```js
* import { Auth } from "@auth/core"
* import Auth0 from "@auth/core/providers/auth0"
*
* const request = new Request("https://example.com")
* const resposne = await Auth(request, {
* providers: [Auth0({ clientId: "", clientSecret: "", issuer: "" })],
* })
* ```
*
* ---
*
* ## Resources
*
* @see [Link 1](https://example.com)
*
* ---
*
* ## Notes
*
* By default, Auth.js assumes that the Auth0 provider is
* based on the [OIDC](https://openid.net/specs/openid-connect-core-1_0.html) specification.
*
* :::tip
*
* The Auth0 provider comes with a [default configuration](https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/providers/auth0.ts).
* To override the defaults for your use case, check out [customizing a built-in OAuth provider](https://authjs.dev/guides/providers/custom-provider#override-default-options).
*
* :::
*
* :::info **Disclaimer**
*
* If you think you found a bug in the default configuration, you can [open an issue](https://authjs.dev/new/provider-issue).
*
* Auth.js strictly adheres to the specification and it cannot take responsibility for any deviation from
* the spec by the provider. You can open an issue, but if the problem is non-compliance with the spec,
* we might not pursue a resolution. You can ask for more help in [Discussions](https://authjs.dev/new/github-discussions).
*
* :::
*/

export default function Auth0<P extends Auth0Profile>(
options: OAuthUserConfig<P>
): OAuthConfig<P> {
Expand Down
26 changes: 19 additions & 7 deletions packages/core/src/providers/github.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
/**
* <div style={{backgroundColor: "#24292f", display: "flex", justifyContent: "space-between", color: "#fff", padding: 16}}>
* <span>Built-in <b>GitHub</b> integration.</span>
* <a href="https://github.com">
* <img style={{display: "block"}} src="https://authjs.dev/img/providers/github-dark.svg" height="48" width="48"/>
* </a>
* </div>
*
* ---
* @module providers/github
*/

import type { OAuthConfig, OAuthUserConfig } from "./index.js"

export interface GithubEmail extends Record<string, any> {
export interface GitHubEmail extends Record<string, any> {
email: string
primary: boolean
verified: boolean
visibility: "public" | "private"
}

/** @see [Get the authenticated user](https://docs.github.com/en/rest/users/users#get-the-authenticated-user) */
export interface GithubProfile extends Record<string, any> {
export interface GitHubProfile extends Record<string, any> {
login: string
id: number
node_id: string
Expand Down Expand Up @@ -64,11 +76,11 @@ export interface GithubProfile extends Record<string, any> {
* @example
*
* ```ts
* import Auth from "@auth/core"
* import { Auth } from "@auth/core"
* import { GitHub } from "@auth/core/providers/github"
*
* const request = new Request("https://example.com")
* const resposne = await AuthHandler(request, {
* const resposne = await Auth(request, {
* providers: [GitHub({ clientId: "", clientSecret: "" })],
* })
* ```
Expand Down Expand Up @@ -103,7 +115,7 @@ export interface GithubProfile extends Record<string, any> {
*
* :::
*/
export default function GitHub<Profile extends GithubProfile>(
export default function GitHub<Profile extends GitHubProfile>(
options: OAuthUserConfig<Profile>
): OAuthConfig<Profile> {
return {
Expand All @@ -130,7 +142,7 @@ export default function GitHub<Profile extends GithubProfile>(
})

if (res.ok) {
const emails: GithubEmail[] = await res.json()
const emails: GitHubEmail[] = await res.json()
profile.email = (emails.find((e) => e.primary) ?? emails[0]).email
}
}
Expand All @@ -150,7 +162,7 @@ export default function GitHub<Profile extends GithubProfile>(
logo: "/github.svg",
logoDark: "/github-dark.svg",
bg: "#fff",
bgDark: "#000",
bgDark: "#24292f",
text: "#000",
textDark: "#fff",
},
Expand Down

0 comments on commit c05951f

Please sign in to comment.