Skip to content

Commit

Permalink
Reddit Audiences - refreshAccessToken fix (#2467)
Browse files Browse the repository at this point in the history
* index

* add fields

* start creating email upload function

* add updateAudience endpoint

* add logic to know which payload arrays to push

* audience update

* testing permissions to collab

* fix array bug and add dynamic ID field

* testing

* resolving errors and adding types + refactor

* few more changes

* generating types

* committing changes

* refactor

* added functions back into the refactored files

* cleaned out excess logs

* tested locally

* removing token

* adding a unit test

* add more test cases and fix email hashing bug

* removing snapshot tests

* fix refresh token function

---------

Co-authored-by: Austin Hsueh <[email protected]>
Co-authored-by: Manik Mehta <[email protected]>
Co-authored-by: ManikMM <[email protected]>
Co-authored-by: Joe Ayoub <[email protected]>
  • Loading branch information
5 people authored Oct 1, 2024
1 parent c6d82fb commit 05d9c2f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const PS_BASE_URL = 'https://api.postscript.io'

export const AUDIENCE_PROPERTY = 'Segment Audiences' as const
export const AUDIENCE_PROPERTY = 'Segment Audiences' as const
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { AUDIENCE_PROPERTY } from './const'

export type SubscriberResp = {
subscribers: Array<Subscriber>
subscribers: Array<Subscriber>
}

export type Subscriber = {
properties?: {
[AUDIENCE_PROPERTY]: string[]
},
id: string
}
properties?: {
[AUDIENCE_PROPERTY]: string[]
}
id: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ const destination: AudienceDestinationDefinition<Settings, AudienceSettings> = {
}
},
refreshAccessToken: async (request, { auth }) => {
const authToken = Buffer.from(`${auth.clientId}:${auth.clientSecret}`).toString('base64')

const res = await request('https://www.reddit.com/api/v1/access_token', {
method: 'POST',
username: auth.clientId,
password: auth.clientSecret,
headers: {
Authorization: `Basic ${authToken}`,
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'segmentaudienceapi:v1 (by /u/segment_audiences)'
},
body: new URLSearchParams({
refresh_token: auth.refreshToken,
grant_type: 'refresh_token'
Expand Down

0 comments on commit 05d9c2f

Please sign in to comment.