-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #808 from streamethorg/develop
Merge dev to main
- Loading branch information
Showing
108 changed files
with
633 additions
and
14,924 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
name: Task | ||
about: Define a new task related to a User Story | ||
title: [TASK] | ||
labels: task | ||
assignees: '' | ||
|
||
--- | ||
|
||
## Description | ||
[Provide a clear and concise description of the task] | ||
|
||
## Related User Story | ||
Include the related User Story #< User Story > | ||
|
||
## Objectives | ||
- [ ] [Objective 1] | ||
- [ ] [Objective 2] | ||
- [ ] [Objective 3] | ||
|
||
## Acceptance Criteria | ||
- [ ] [Criterion 1] | ||
- [ ] [Criterion 2] | ||
- [ ] [Criterion 3] | ||
|
||
## Additional Information | ||
[Any extra details, context, or resources that might be helpful] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { apiUrl } from '@/lib/utils/utils' | ||
import { revalidatePath } from 'next/cache' | ||
import { cookies } from 'next/headers' | ||
import { redirect } from 'next/navigation' | ||
import { NextRequest, NextResponse } from 'next/server' | ||
import { | ||
createOAuth, | ||
getUserProfileImage, | ||
} from '@/lib/utils/twitterAuth' | ||
|
||
export async function GET(request: NextRequest) { | ||
const searchParams = request.nextUrl.searchParams | ||
const oauthToken = searchParams.get('oauth_token') | ||
const oauthVerifier = searchParams.get('oauth_verifier') | ||
const redirectUrl = decodeURIComponent( | ||
searchParams.get('redirectUrl')! | ||
) | ||
const organizationId = searchParams.get('organizationId') | ||
const authToken = cookies().get('user-session')?.value | ||
const originUrl = process.env.NEXT_PUBLIC_ORIGIN_URL! | ||
|
||
if (!oauthToken || !authToken) { | ||
console.error('Twitter oauth token does not exist') | ||
return redirect(originUrl + redirectUrl) | ||
} | ||
|
||
const oauth = createOAuth() | ||
const url = 'https://api.twitter.com/oauth/access_token' | ||
const method = 'POST' | ||
const requestData = { | ||
url, | ||
method, | ||
data: { oauth_token: oauthToken, oauth_verifier: oauthVerifier }, | ||
} | ||
const headers = oauth.toHeader(oauth.authorize(requestData)) | ||
try { | ||
const responseToken = await fetch(url, { | ||
method: 'POST', | ||
headers: { | ||
'content-type': 'application/json', | ||
...headers, | ||
}, | ||
}) | ||
|
||
const responseText = await responseToken.text() | ||
const responseParams = new URLSearchParams(responseText) | ||
const oauthAccessToken = responseParams.get('oauth_token') | ||
const oauthAccessTokenSecret = responseParams.get( | ||
'oauth_token_secret' | ||
) | ||
const userId = responseParams.get('user_id') | ||
const screenName = responseParams.get('screen_name') | ||
// if (!screenName) { | ||
// throw new Error(`Screen name not found`) | ||
// } | ||
// const userProfileImageUrl = await getUserProfileImage(screenName) | ||
|
||
const response = await fetch( | ||
`${apiUrl()}/organizations/socials/${organizationId}`, | ||
{ | ||
method: 'PUT', | ||
cache: 'no-cache', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${authToken}`, | ||
}, | ||
body: JSON.stringify({ | ||
type: 'twitter', | ||
accessToken: oauthAccessToken, | ||
refreshToken: oauthAccessTokenSecret, | ||
expireTime: Math.floor(Date.now() / 1000), | ||
name: screenName, | ||
thumbnail: '', | ||
channelId: userId, | ||
}), | ||
} | ||
) | ||
|
||
revalidatePath('/studio') | ||
return NextResponse.redirect( | ||
new URL(originUrl + redirectUrl, request.url) | ||
) | ||
} catch (err) { | ||
return NextResponse.json( | ||
{ error: err }, | ||
{ | ||
status: 500, | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { NextRequest, NextResponse } from 'next/server' | ||
import { createOAuth } from '@/lib/utils/twitterAuth' | ||
|
||
export async function GET(request: NextRequest) { | ||
const searchParams = request.nextUrl.searchParams | ||
const state = searchParams.get('state') | ||
const TWITTER_CALLBACK_URL = process.env.TWITTER_CALLBACK_URL! | ||
const TWITTER_ACCESS_TOKEN = process.env.TWITTER_ACCESS_TOKEN! | ||
const TWITTER_ACCESS_TOKEN_SECRET = | ||
process.env.TWITTER_ACCESS_TOKEN_SECRET! | ||
|
||
const method = 'POST' | ||
const url = 'https://api.twitter.com/oauth/request_token' | ||
const decodedState = state | ||
? JSON.parse(decodeURIComponent(state)) | ||
: '' | ||
|
||
const callbackUrlWithParams = new URL(TWITTER_CALLBACK_URL) | ||
// Add personal redirect parameters to the callback URL | ||
Object.keys(decodedState).forEach((key) => { | ||
callbackUrlWithParams.searchParams.append(key, decodedState[key]) | ||
}) | ||
const callback = encodeURI(callbackUrlWithParams.toString()) | ||
|
||
const oauth = createOAuth() | ||
|
||
const requestData = { | ||
url, | ||
method, | ||
data: { oauth_callback: callback }, | ||
} | ||
const token = { | ||
key: TWITTER_ACCESS_TOKEN, | ||
secret: TWITTER_ACCESS_TOKEN_SECRET, | ||
} | ||
const headers = oauth.toHeader(oauth.authorize(requestData, token)) | ||
|
||
try { | ||
const response = await fetch(url, { | ||
method, | ||
headers: { | ||
'content-type': 'application/json', | ||
...headers, | ||
}, | ||
}) | ||
|
||
const responseText = await response.text() | ||
const responseParams = new URLSearchParams(responseText) | ||
const oauthToken = responseParams.get('oauth_token') | ||
|
||
return NextResponse.redirect( | ||
new URL( | ||
`https://api.twitter.com/oauth/authorize?oauth_token=${oauthToken}`, | ||
request.url | ||
) | ||
) | ||
} catch (err) { | ||
return NextResponse.json( | ||
{ error: err }, | ||
{ | ||
status: 500, | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.