@@ -19,23 +19,23 @@ export interface OAuthInstagramConfig {
19
19
clientSecret ?: string
20
20
/**
21
21
* Instagram OAuth Scope
22
- * @default [ 'user_profile ' ]
22
+ * @required [ 'business_basic ' ]
23
23
* @see https://developers.facebook.com/docs/instagram-basic-display-api/overview#permissions
24
- * @example [ 'user_profile ', 'user_media ' ],
24
+ * @example [ 'business_basic ', 'business_manage_messages ' ],
25
25
*/
26
- scope ?: string [ ]
26
+ scope ?: ( 'business_basic' | 'business_content_publish' | 'business_manage_comments' | 'business_manage_messages' ) [ ]
27
27
28
28
/**
29
29
* Instagram OAuth User Fields
30
30
* @default [ 'id', 'username'],
31
31
* @see https://developers.facebook.com/docs/instagram-basic-display-api/reference/user#fields
32
- * @example [ 'id', 'username', 'account_type', 'media_count ' ],
32
+ * @example [ 'id', 'username', 'user_id', ' account_type', 'profile_picture_url ' ],
33
33
*/
34
- fields ?: string [ ]
34
+ fields ?: ( 'id' | 'user_id' | 'username' | 'name' | 'account_type' | 'profile_picture_url' | 'followers_count' | 'follows_count' | 'media_count' ) [ ]
35
35
36
36
/**
37
37
* Instagram OAuth Authorization URL
38
- * @default 'https://api .instagram.com/oauth/authorize'
38
+ * @default 'https://www .instagram.com/oauth/authorize'
39
39
*/
40
40
authorizationURL ?: string
41
41
@@ -64,19 +64,28 @@ export function defineOAuthInstagramEventHandler({
64
64
} : OAuthConfig < OAuthInstagramConfig > ) {
65
65
return eventHandler ( async ( event : H3Event ) => {
66
66
config = defu ( config , useRuntimeConfig ( event ) . oauth ?. instagram , {
67
- scope : [ 'user_profile ' ] ,
68
- authorizationURL : 'https://api .instagram.com/oauth/authorize' ,
67
+ scope : [ 'business_basic ' ] ,
68
+ authorizationURL : 'https://www .instagram.com/oauth/authorize' ,
69
69
tokenURL : 'https://api.instagram.com/oauth/access_token' ,
70
70
authorizationParams : { } ,
71
71
} ) as OAuthInstagramConfig
72
72
73
- const query = getQuery < { code ?: string , error ?: string } > ( event )
73
+ const query = getQuery < {
74
+ code ?: string
75
+ error ?: string
76
+ error_reason ?: string
77
+ error_description ?: string
78
+ } > ( event )
74
79
75
80
if ( query . error ) {
76
81
const error = createError ( {
77
82
statusCode : 401 ,
78
83
message : `Instagram login failed: ${ query . error || 'Unknown error' } ` ,
79
- data : query ,
84
+ data : {
85
+ error : query . error ,
86
+ error_reason : query . error_reason ,
87
+ error_description : query . error_description ,
88
+ } ,
80
89
} )
81
90
if ( ! onError ) throw error
82
91
return onError ( event , error )
@@ -96,7 +105,7 @@ export function defineOAuthInstagramEventHandler({
96
105
withQuery ( config . authorizationURL as string , {
97
106
client_id : config . clientId ,
98
107
redirect_uri : redirectURL ,
99
- scope : config . scope . join ( ' ' ) ,
108
+ scope : config . scope . join ( ) ,
100
109
response_type : 'code' ,
101
110
} ) ,
102
111
)
@@ -120,10 +129,10 @@ export function defineOAuthInstagramEventHandler({
120
129
// TODO: improve typing
121
130
122
131
config . fields = config . fields || [ 'id' , 'username' ]
123
- const fields = config . fields . join ( ',' )
132
+ const fields = config . fields . join ( )
124
133
125
134
const user = await $fetch (
126
- `https://graph.instagram.com/v20 .0/me?fields=${ fields } &access_token=${ accessToken } ` ,
135
+ `https://graph.instagram.com/v21 .0/me?fields=${ fields } &access_token=${ accessToken } ` ,
127
136
)
128
137
129
138
if ( ! user ) {
0 commit comments