@@ -11,19 +11,11 @@ import
1111
1212import { AddressInfo } from 'net' ;
1313
14- import
15- {
16- AccessToken ,
17- AuthorizationTokenConfig ,
18- create ,
19- ModuleOptions ,
20- OAuthClient ,
21- Token
22- } from 'simple-oauth2' ;
14+ import * as OAuth from 'simple-oauth2' ;
2315
2416import { format as formatUrl } from 'url' ;
2517
26- import { PatreonRequest , Endpoints , Schemas } from "../../../dist/patreon" ;
18+ import { PatreonRequest , Endpoints , Schemas , Types , Data } from "../../../dist/patreon" ;
2719import { ParsedUrlQueryInput } from 'querystring' ;
2820
2921dotenv . config ( { path : "./.env" } ) ;
@@ -32,18 +24,20 @@ const PATREON_HOST: string = "https://www.patreon.com";
3224const PATREON_TOKEN_PATH : string = "/api/oauth2/token" ;
3325const PATREON_AUTHORIZE_PATH : string = "/oauth2/authorize" ;
3426
27+ const PORT : number = 8085 ;
28+
3529const authorizeRedirectUri : string = formatUrl ( {
3630 protocol : "http" ,
37- host : " localhost:8081" ,
31+ host : ` localhost:${ PORT } ` ,
3832 pathname : "/oauth/redirect" ,
3933} ) ;
4034
4135const stateCheck : string = "chill" ;
4236const scopes : string = "identity campaigns identity.memberships campaigns.members" ;
4337
44- let accessTokenStore : AccessToken ;
38+ let accessTokenStore : Types . PatreonToken ;
4539
46- const credentials : ModuleOptions = {
40+ const credentials : OAuth . ModuleOptions = {
4741 client :
4842 {
4943 id : process . env . PATREON_CLIENT_ID as string ,
@@ -58,19 +52,21 @@ const credentials: ModuleOptions = {
5852} ;
5953
6054// Build the OAuth2 client.
61- const client : OAuthClient < "patreon" > = create ( credentials ) ;
55+ const client : OAuth . AuthorizationCode < "patreon" > = new OAuth . AuthorizationCode ( credentials ) ;
6256
6357export async function ShowPatronInformation ( _req : Request , res : Response ) : Promise < void >
6458{
6559 if ( accessTokenStore )
6660 {
67- const UserQueryObject : Schemas . User = new Schemas . User (
61+ var schemaObject =
62+ {
63+ attributes :
6864 {
69- attributes :
70- {
71- about : Schemas . user_constants . attributes ?. about ,
72- } ,
73- } ) ;
65+ about : Schemas . user_constants . attributes ?. about ,
66+ }
67+ } ;
68+
69+ const UserQueryObject : Schemas . User = new Schemas . User ( schemaObject ) ;
7470
7571 const endpointQuery : ParsedUrlQueryInput = Endpoints . BuildEndpointQuery ( UserQueryObject ) ;
7672
@@ -79,7 +75,8 @@ export async function ShowPatronInformation(_req: Request, res: Response): Promi
7975 endpointQuery ) ;
8076
8177 const result : string = await PatreonRequest ( accessTokenStore , query ) ;
82- const obj : any = JSON . parse ( result ) ;
78+
79+ var userObject : Data . User = new Data . User ( JSON . parse ( result ) ) ;
8380 res . send ( `
8481 <html>
8582 <head>
@@ -88,10 +85,10 @@ export async function ShowPatronInformation(_req: Request, res: Response): Promi
8885 </style>
8986 </head>
9087 <body>
91- <pre>${ JSON . stringify ( obj , null , ' ' ) } </pre>
88+ <pre>${ JSON . stringify ( userObject , null , ' ' ) } </pre>
9289 </body>
9390 </html>` ) ;
94- console . log ( JSON . stringify ( obj , null , ' ' ) ) ;
91+ console . log ( JSON . stringify ( userObject , null , ' ' ) ) ;
9592 }
9693 else
9794 {
@@ -103,7 +100,7 @@ export async function ShowPatronInformation(_req: Request, res: Response): Promi
103100export function PatreonAuthorizeMiddleware ( _req : Request , res : Response ) : void
104101{
105102 // Build AuthorizationUrl
106- const authorizationUri : string = client . authorizationCode . authorizeURL (
103+ const authorizationUri : string = client . authorizeURL (
107104 {
108105 redirect_uri : authorizeRedirectUri ,
109106 scope : scopes ,
@@ -117,7 +114,7 @@ export function PatreonAuthorizeMiddleware(_req: Request, res: Response): void
117114// Patreon Redirect Flow Entrypoint
118115export async function PatreonRedirectMiddleware ( req : Request , res : Response , next : NextFunction ) : Promise < void >
119116{
120- let tokenConfig : AuthorizationTokenConfig ;
117+ let tokenConfig : OAuth . AuthorizationTokenConfig ;
121118 let stateVar : string ;
122119 {
123120 const
@@ -143,8 +140,9 @@ export async function PatreonRedirectMiddleware(req: Request, res: Response, nex
143140 // Save the access token
144141 try
145142 {
146- const result : Token = await client . authorizationCode . getToken ( tokenConfig ) ;
147- accessTokenStore = client . accessToken . create ( result ) ;
143+ const result : OAuth . Token = await client . getToken ( tokenConfig ) ;
144+ accessTokenStore = Types . CreatePatreonTokenFromOAuthToken ( client . createToken ( result ) ) ;
145+
148146 console . log ( accessTokenStore ) ;
149147 res . redirect ( "/" ) ;
150148 }
@@ -156,7 +154,6 @@ export async function PatreonRedirectMiddleware(req: Request, res: Response, nex
156154 }
157155}
158156
159- const PORT : number = 8081 ;
160157const app : express . Express = express ( ) ;
161158const server = app . listen ( PORT , ( ) =>
162159{
0 commit comments