Skip to content

Commit 9d7cbc5

Browse files
committed
feat(provider): Adding login with amazon OAuth2 provider
1 parent c7c2cfa commit 9d7cbc5

5 files changed

Lines changed: 214 additions & 0 deletions

File tree

.github/ISSUE_TEMPLATE/2_bug_provider.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ body:
2424
- "Email"
2525
- "Custom provider"
2626
- "42 School"
27+
- "Amazon"
2728
- "Apple"
2829
- "Asgardeo"
2930
- "Atlassian"

docs/pages/data/manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"twitter": "Twitter",
4949
"apple": "Apple",
5050
"discord": "Discord",
51+
"amazon": "Amazon",
5152
"auth0": "Auth0",
5253
"facebook": "Facebook",
5354
"keycloak": "Keycloak",
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import { Callout } from "nextra/components"
2+
import { Code } from "@/components/Code"
3+
4+
<img align="right" src="/img/providers/amazon.svg" height="64" width="64" />
5+
6+
# Amazon Provider
7+
8+
## Resources
9+
10+
- [Amazon OAuth documentation](https://developer.amazon.com/docs/login-with-amazon/documentation-overview.html)
11+
12+
## Setup
13+
14+
### Callback URL
15+
16+
<Code>
17+
<Code.Express>
18+
19+
```bash
20+
https://example.com/api/auth/callback/amazon
21+
```
22+
23+
</Code.Express>
24+
<Code.Next>
25+
26+
```bash
27+
https://example.com/auth/callback/amazon
28+
```
29+
30+
</Code.Next>
31+
<Code.Qwik>
32+
33+
```bash
34+
https://example.com/auth/callback/amazon
35+
```
36+
37+
</Code.Qwik>
38+
<Code.Svelte>
39+
40+
```bash
41+
https://example.com/auth/callback/amazon
42+
```
43+
44+
</Code.Svelte>
45+
</Code>
46+
47+
### Environment Variables
48+
49+
```
50+
AUTH_AMAZON_ID
51+
AUTH_AMAZON_SECRET
52+
```
53+
54+
### Configuration
55+
56+
<Code>
57+
<Code.Next>
58+
59+
```ts filename="/auth.ts"
60+
import NextAuth from "next-auth"
61+
import Amazon from "next-auth/providers/amazon"
62+
63+
export const { handlers, auth, signIn, signOut } = NextAuth({
64+
providers: [Amazon],
65+
})
66+
```
67+
68+
</Code.Next>
69+
<Code.Qwik>
70+
71+
```ts filename="/src/routes/plugin@auth.ts"
72+
import { QwikAuth$ } from "@auth/qwik"
73+
import Amazon from "@auth/qwik/providers/amazon"
74+
75+
export const { onRequest, useSession, useSignIn, useSignOut } = QwikAuth$(
76+
() => ({
77+
providers: [Amazon],
78+
})
79+
)
80+
```
81+
82+
</Code.Qwik>
83+
<Code.Svelte>
84+
85+
```ts filename="/src/auth.ts"
86+
import { SvelteKitAuth } from "@auth/sveltekit"
87+
import Amazon from "@auth/sveltekit/providers/amazon"
88+
89+
export const { handle, signIn, signOut } = SvelteKitAuth({
90+
providers: [Amazon],
91+
})
92+
```
93+
94+
</Code.Svelte>
95+
<Code.Express>
96+
97+
```ts filename="/src/app.ts"
98+
import { ExpressAuth } from "@auth/express"
99+
import Amazon from "@auth/express/providers/amazon"
100+
101+
app.use("/auth/*", ExpressAuth({ providers: [Amazon] }))
102+
```
103+
104+
</Code.Express>
105+
</Code>
106+
107+
### Notes
108+
109+
- The Amazon provider requires you to set up your application in the [Amazon Developer Console - Login with Amazon](https://developer.amazon.com/loginwithamazon/console/site/lwa/overview.html).
110+
- Make sure to configure the correct callback URL in your Amazon app settings, which should match the one provided by your application (e.g., `https://example.com/auth/callback/amazon` for Next.js).
Lines changed: 13 additions & 0 deletions
Loading
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* <div class="provider" style={{backgroundColor: "#000", display: "flex", justifyContent: "space-between", color: "#fff", padding: 16}}>
3+
* <span>Built-in <b>Amazon</b> integration.</span>
4+
* <a href="https://amazon.com">
5+
* <img style={{display: "block"}} src="https://authjs.dev/img/providers/amazon.svg" height="48" width="48"/>
6+
* </a>
7+
* </div>
8+
* @module providers/amazon
9+
*/
10+
import type { OAuthConfig, OAuthUserConfig } from "./index.js"
11+
12+
export interface AmazonProfile extends Record<string, any> {
13+
email: string
14+
name: string
15+
user_id: string
16+
postal_code?: string
17+
}
18+
19+
/**
20+
* Add "Login with Amazon" login to your page.
21+
*
22+
* ### Setup
23+
*
24+
* #### Callback URL
25+
* ```
26+
* https://example.com/auth/callback/amazon
27+
* ```
28+
*
29+
* For Express.js or Next.js Pages Router, use:
30+
* ```
31+
* https://example.com/api/auth/callback/amazon
32+
* ```
33+
*
34+
* ### Configuration
35+
*```ts
36+
* import { Auth } from "@auth/core"
37+
* import Amazon from "@auth/core/providers/amazon"
38+
*
39+
* const request = new Request(origin)
40+
* const response = await Auth(request, {
41+
* providers: [
42+
* Amazon({
43+
* clientId: AUTH_AMAZON_ID,
44+
* clientSecret: AUTH_AMAZON_SECRET,
45+
* }),
46+
* ],
47+
* })
48+
* ```
49+
*
50+
* ### Resources
51+
* - [Login with Amazon documentation](https://developer.amazon.com/docs/login-with-amazon/documentation-overview.html)
52+
*
53+
* ### Bug reports
54+
* If you encounter issues with this provider, please check the Auth.js documentation and open an issue in the Auth.js repository with details about your configuration and error.
55+
*
56+
* ### Customization
57+
* If you need to override this provider's defaults, follow the Auth.js guide on customizing built-in OAuth providers.
58+
*/
59+
export default function Amazon<P extends AmazonProfile>(
60+
options: OAuthUserConfig<P>
61+
): OAuthConfig<P> {
62+
return {
63+
id: "amazon",
64+
name: "Amazon",
65+
type: "oauth",
66+
authorization: {
67+
// https://developer.amazon.com/docs/login-with-amazon/authorization-code-grant.html
68+
url: "https://www.amazon.com/ap/oa",
69+
params: {
70+
scope: "profile",
71+
},
72+
},
73+
// https://developer.amazon.com/docs/login-with-amazon/authorization-code-grant.html#access-token-request
74+
token: "https://api.amazon.com/auth/o2/token",
75+
// https://developer.amazon.com/docs/login-with-amazon/obtain-customer-profile.html
76+
userinfo: "https://api.amazon.com/user/profile",
77+
profile(profile: P) {
78+
// https://developer.amazon.com/docs/login-with-amazon/customer-profile.html
79+
return {
80+
id: profile.user_id,
81+
name: profile.name,
82+
email: profile.email,
83+
image: null,
84+
}
85+
},
86+
style: { brandColor: "#ff9900" },
87+
options,
88+
}
89+
}

0 commit comments

Comments
 (0)