Skip to content

Commit

Permalink
Add fetch authorization url
Browse files Browse the repository at this point in the history
Add fetch authorization url
  • Loading branch information
Shreyaschorge authored Apr 12, 2024
2 parents 84b2040 + 19b734d commit 137e190
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@neynar/nodejs-sdk",
"version": "1.17.0",
"version": "1.18.0",
"description": "SDK to interact with Neynar APIs (https://docs.neynar.com/)",
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions src/neynar-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export {
ReactionType,
FrameButtonActionType,
ValidateFrameAnalyticsType,
AuthorizationUrlResponseType,
} from "./v2";
export {
TimeWindow,
Expand Down
32 changes: 31 additions & 1 deletion src/neynar-api/neynar-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ import {
FrameValidateAnalyticsResponse,
ValidateFrameAnalyticsType,
FrameValidateListResponse,
AuthorizationUrlResponse,
AuthorizationUrlResponseType,
} from "./v2/openapi-farcaster";

import {
Expand Down Expand Up @@ -1277,7 +1279,7 @@ export class NeynarAPIClient {
): Promise<ChannelListResponse> {
return await this.clients.v2.fetchUserChannels(fid, options);
}

/**
* Searches for users based on a query. This method is used to find users by usernames or other
* identifiable information. The search can be contextualized to the viewer specified by `viewerFid`.
Expand Down Expand Up @@ -1367,6 +1369,34 @@ export class NeynarAPIClient {
return await this.clients.v2.lookupUserByCustodyAddress(custodyAddress);
}

/**
* Fetch authorization url (Fetched authorized url useful for SIWN login operation)
*
* @param {string} client_id - The client identifier registered with the API.
* @param {AuthorizationUrlResponseType} code - The type of response to be received, typically including tokens.
*
* @returns {Promise<AuthorizationUrlResponse>} A promise that resolves to an object containing the authorization URL.
*
* @example
* // Example: Fetch the authorization URL
* import { AuthorizationUrlResponseType } from "@neynar/nodejs-sdk";
*
* client.fetchAuthorizationUrl('your-client-id', AuthorizationUrlResponseType.Code).then(response => {
* console.log('Authorization URL:', response); // Outputs the fetched URL
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/fetch-authorization-url).
*/
public async fetchAuthorizationUrl(
client_id: string,
response_type: AuthorizationUrlResponseType
): Promise<AuthorizationUrlResponse> {
return await this.clients.v2.fetchAuthorizationUrl(
client_id,
response_type
);
}

// ------------ Cast ------------

/**
Expand Down
60 changes: 46 additions & 14 deletions src/neynar-api/v2/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ import {
FrameValidateListResponse,
ValidateFrameAnalyticsType,
FrameValidateAnalyticsResponse,
AuthorizationUrlResponse,
AuthorizationUrlResponseType,
} from "./openapi-farcaster";
import axios, { AxiosError, AxiosInstance } from "axios";
import { silentLogger, Logger } from "../common/logger";
Expand Down Expand Up @@ -767,21 +769,21 @@ export class NeynarV2APIClient {
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/user-channels).
*/
public async fetchUserChannels(
fid: number,
options?: {
limit?: number;
cursor?: string;
}
): Promise<ChannelListResponse> {
const response = await this.apis.user.userChannels(
this.apiKey,
fid,
options?.limit,
options?.cursor
);
return response.data;
public async fetchUserChannels(
fid: number,
options?: {
limit?: number;
cursor?: string;
}
): Promise<ChannelListResponse> {
const response = await this.apis.user.userChannels(
this.apiKey,
fid,
options?.limit,
options?.cursor
);
return response.data;
}

/**
* Fetches bulk user information based on multiple Ethereum addresses. This function is particularly
Expand Down Expand Up @@ -895,6 +897,36 @@ export class NeynarV2APIClient {
return response.data;
}

/**
* Fetch authorization url (Fetched authorized url useful for SIWN login operation)
*
* @param {string} client_id - The client identifier registered with the API.
* @param {AuthorizationUrlResponseType} code - The type of response to be received, typically including tokens.
*
* @returns {Promise<AuthorizationUrlResponse>} A promise that resolves to an object containing the authorization URL.
*
* @example
* // Example: Fetch the authorization URL
* import { AuthorizationUrlResponseType } from "@neynar/nodejs-sdk";
*
* client.fetchAuthorizationUrl('your-client-id', AuthorizationUrlResponseType.Code).then(response => {
* console.log('Authorization URL:', response); // Outputs the fetched URL
* });
*
* For more information, refer to the [API documentation](https://docs.neynar.com/reference/fetch-authorization-url).
*/
public async fetchAuthorizationUrl(
client_id: string,
code: AuthorizationUrlResponseType
): Promise<AuthorizationUrlResponse> {
const response = await this.apis.user.fetchAuthorizationUrl(
this.apiKey,
client_id,
code
);
return response.data;
}

// ------------ Cast ------------

/**
Expand Down
2 changes: 2 additions & 0 deletions src/neynar-api/v2/openapi-farcaster/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ git_push.sh
index.ts
models/active-status.ts
models/add-verification-req-body.ts
models/authorization-url-response-type.ts
models/authorization-url-response.ts
models/bulk-casts-response.ts
models/bulk-follow-response.ts
models/bulk-users-response.ts
Expand Down
94 changes: 94 additions & 0 deletions src/neynar-api/v2/openapi-farcaster/apis/user-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } fr
// @ts-ignore
import { AddVerificationReqBody } from '../models';
// @ts-ignore
import { AuthorizationUrlResponse } from '../models';
// @ts-ignore
import { AuthorizationUrlResponseType } from '../models';
// @ts-ignore
import { BulkFollowResponse } from '../models';
// @ts-ignore
import { BulkUsersResponse } from '../models';
Expand Down Expand Up @@ -192,6 +196,57 @@ export const UserApiAxiosParamCreator = function (configuration?: Configuration)
options: localVarRequestOptions,
};
},
/**
* Fetch authorization url (Fetched authorized url useful for SIWN login operation)
* @summary Fetch authorization url
* @param {string} apiKey API key required for authentication.
* @param {string} clientId
* @param {AuthorizationUrlResponseType} responseType
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
fetchAuthorizationUrl: async (apiKey: string, clientId: string, responseType: AuthorizationUrlResponseType, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'apiKey' is not null or undefined
assertParamExists('fetchAuthorizationUrl', 'apiKey', apiKey)
// verify required parameter 'clientId' is not null or undefined
assertParamExists('fetchAuthorizationUrl', 'clientId', clientId)
// verify required parameter 'responseType' is not null or undefined
assertParamExists('fetchAuthorizationUrl', 'responseType', responseType)
const localVarPath = `/farcaster/login/authorize`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

if (clientId !== undefined) {
localVarQueryParameter['client_id'] = clientId;
}

if (responseType !== undefined) {
localVarQueryParameter['response_type'] = responseType;
}

if (apiKey != null) {
localVarHeaderParameter['api_key'] = String(apiKey);
}



setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
* Follow a user \\ (In order to follow a user `signer_uuid` must be approved)
* @summary Follow a user
Expand Down Expand Up @@ -750,6 +805,19 @@ export const UserApiFp = function(configuration?: Configuration) {
const localVarAxiosArgs = await localVarAxiosParamCreator.farcasterUserVerificationPost(apiKey, addVerificationReqBody, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
* Fetch authorization url (Fetched authorized url useful for SIWN login operation)
* @summary Fetch authorization url
* @param {string} apiKey API key required for authentication.
* @param {string} clientId
* @param {AuthorizationUrlResponseType} responseType
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async fetchAuthorizationUrl(apiKey: string, clientId: string, responseType: AuthorizationUrlResponseType, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<AuthorizationUrlResponse>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.fetchAuthorizationUrl(apiKey, clientId, responseType, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
* Follow a user \\ (In order to follow a user `signer_uuid` must be approved)
* @summary Follow a user
Expand Down Expand Up @@ -933,6 +1001,18 @@ export const UserApiFactory = function (configuration?: Configuration, basePath?
farcasterUserVerificationPost(apiKey: string, addVerificationReqBody: AddVerificationReqBody, options?: any): AxiosPromise<OperationResponse> {
return localVarFp.farcasterUserVerificationPost(apiKey, addVerificationReqBody, options).then((request) => request(axios, basePath));
},
/**
* Fetch authorization url (Fetched authorized url useful for SIWN login operation)
* @summary Fetch authorization url
* @param {string} apiKey API key required for authentication.
* @param {string} clientId
* @param {AuthorizationUrlResponseType} responseType
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
fetchAuthorizationUrl(apiKey: string, clientId: string, responseType: AuthorizationUrlResponseType, options?: any): AxiosPromise<AuthorizationUrlResponse> {
return localVarFp.fetchAuthorizationUrl(apiKey, clientId, responseType, options).then((request) => request(axios, basePath));
},
/**
* Follow a user \\ (In order to follow a user `signer_uuid` must be approved)
* @summary Follow a user
Expand Down Expand Up @@ -1111,6 +1191,20 @@ export class UserApi extends BaseAPI {
return UserApiFp(this.configuration).farcasterUserVerificationPost(apiKey, addVerificationReqBody, options).then((request) => request(this.axios, this.basePath));
}

/**
* Fetch authorization url (Fetched authorized url useful for SIWN login operation)
* @summary Fetch authorization url
* @param {string} apiKey API key required for authentication.
* @param {string} clientId
* @param {AuthorizationUrlResponseType} responseType
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof UserApi
*/
public fetchAuthorizationUrl(apiKey: string, clientId: string, responseType: AuthorizationUrlResponseType, options?: AxiosRequestConfig) {
return UserApiFp(this.configuration).fetchAuthorizationUrl(apiKey, clientId, responseType, options).then((request) => request(this.axios, this.basePath));
}

/**
* Follow a user \\ (In order to follow a user `signer_uuid` must be approved)
* @summary Follow a user
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* tslint:disable */
/* eslint-disable */
/**
* Farcaster API V2
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 2.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/



/**
*
* @export
* @enum {string}
*/

export const AuthorizationUrlResponseType = {
Code: 'code'
} as const;

export type AuthorizationUrlResponseType = typeof AuthorizationUrlResponseType[keyof typeof AuthorizationUrlResponseType];



Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* tslint:disable */
/* eslint-disable */
/**
* Farcaster API V2
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 2.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/



/**
*
* @export
* @interface AuthorizationUrlResponse
*/
export interface AuthorizationUrlResponse {
/**
*
* @type {string}
* @memberof AuthorizationUrlResponse
*/
'authorization_url': string;
}

2 changes: 2 additions & 0 deletions src/neynar-api/v2/openapi-farcaster/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export * from './active-status';
export * from './add-verification-req-body';
export * from './authorization-url-response';
export * from './authorization-url-response-type';
export * from './bulk-casts-response';
export * from './bulk-follow-response';
export * from './bulk-users-response';
Expand Down

0 comments on commit 137e190

Please sign in to comment.