Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Nishchit14 committed Sep 21, 2022
2 parents 8853596 + 45956c6 commit 893db86
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const Statistics: FC<any> = () => {
className="m-4 !w-auto"
type="info"
title="Coming soon!!"
description={`Firecamp Team is building this feature and it’ll be releasing very soon. Keep your eyes open at <span> <a href="https://github.com/firecamp-io/firecamp/releases" target="_blank">
description={`Firecamp team is building this feature and it’ll be releasing very soon. Keep us watching on <span> <a href="https://github.com/firecamp-io/firecamp/releases" target="_blank">
Github </a>, <a href="https://twitter.com/FirecampHQ" target="_blank">Twitter</a>, <a href="https://discord.com/invite/8hRaqhK" target="_blank"> Discord</a> </span>.`}
/>
</Container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { EAuthTypes } from '@firecamp/types';
import { _env, _object } from '@firecamp/utils';

const Auth: FC<IAuth> = ({ project = {}, collectionId = '' }) => {
const _getAuthHeaders = new AuthService();
// const _getAuthHeaders = new AuthService();

let [initialAuthDetails, setInitialAuthDetails] = useState({
auth: project?.auth || {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { cloneDeep } from 'lodash';
import { _env, _object } from '@firecamp/utils';

const Auth: FC<IAuth> = ({ module = {}, folderId = '' }) => {
const _getAuthHeaders = new AuthService();
// const _getAuthHeaders = new AuthService();

let [initialAuthDetails, setInitialAuthDetails] = useState(
cloneDeep({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Notification: FC<any> = ({}) => {
<Notes
type="info"
title="Coming soon!!"
description={`Firecamp Team is building this feature and it’ll be releasing very soon. Keep your eyes open at <span> <a href="https://github.com/firecamp-io/firecamp/releases" target="_blank">
description={`Firecamp team is building this feature and it’ll be releasing very soon. Keep us watching on <span> <a href="https://github.com/firecamp-io/firecamp/releases" target="_blank">
Github </a>, <a href="https://twitter.com/FirecampHQ" target="_blank">Twitter</a>, <a href="https://discord.com/invite/8hRaqhK" target="_blank"> Discord</a> </span>.`}
/>
</Container>
Expand Down
2 changes: 1 addition & 1 deletion packages/firecamp-rest/.cspell.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1",
"version": "0.2",
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json",
"language": "en",
"words": [
Expand Down
34 changes: 8 additions & 26 deletions packages/firecamp-rest/src/services/auth/helpers/oauth1.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IOAuth1, EOAuth1Signature } from '@firecamp/types';
import crypto from 'crypto';
import OAuth from 'oauth-1.0a';
import { IOAuth1, EOAuth1Signature } from '@firecamp/types';
import { IExtra } from '../types';

export default (credentials: IOAuth1, extra: IExtra): string => {
Expand Down Expand Up @@ -51,37 +51,19 @@ export default (credentials: IOAuth1, extra: IExtra): string => {

const requestData = {
url: url.raw,
method: method,
method,
data: {
oauth_callback: '',
oauth_timestamp: '',
oauth_nonce: '',
oauth_verifier: '',
oauth_callback: callback_url || '',
oauth_timestamp: timestamp || '',
oauth_nonce: nonce || '',
oauth_verifier: verifier || '',
},
};

if (callback_url) requestData.data.oauth_callback = callback_url;

if (timestamp) requestData.data.oauth_timestamp = timestamp;

if (nonce) requestData.data.oauth_nonce = nonce;

if (verifier) requestData.data.oauth_verifier = verifier;

let token = null;

if (token_key && token_secret) {
token = {
key: token_key,
secret: token_secret,
};
} else if (token_key) {
token = { key: token_key };
}
let token: { key: string, secret: string } = { key: token_key, secret: token_secret };

const data = oauth.authorize(requestData, token);

let authInfo = oauth.toHeader(data).Authorization;
const authInfo = oauth.toHeader(data).Authorization;

// TODO: Review before remove
// authInfo = authInfo.replace(/%7B%7B/g, '{{')
Expand Down
31 changes: 16 additions & 15 deletions packages/firecamp-rest/src/services/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
import { EAuthTypes } from '@firecamp/types';
import { EAuthTypes, EHttpMethod, IAuthAws4, IAuthBasic, IAuthBearer, IAuthDigest, IOAuth1, IOAuth2, IUrl } from '@firecamp/types';
import { IAuthHeader, IExtra, TAuth } from './types';
import { aws4, basic, bearer, digest, oauth1, oauth2 } from './helpers';

export default class Auth {
authType: EAuthTypes;
credentials: TAuth;
extra: IExtra;
authDetails: string | any;
authHeader: string;
aws4AuthHeaders: { [k: string]: any };

constructor(credentials: TAuth, extra: IExtra) {
constructor(authType: EAuthTypes, credentials: TAuth, extra: IExtra) {
this.authType = authType;
this.credentials = credentials;
this.extra = extra;
}

async authorize(): Promise<void> {
switch (this.extra.authType) {
switch (this.authType) {
case EAuthTypes.Aws4:
this.authDetails = aws4(this.credentials, this.extra);
this.aws4AuthHeaders = aws4(this.credentials as IAuthAws4, this.extra);
break;
case EAuthTypes.Basic:
this.authDetails = basic(this.credentials);
this.authHeader = basic(this.credentials as IAuthBasic);
break;
case EAuthTypes.Bearer:
this.authDetails = bearer(this.credentials);
this.authHeader = bearer(this.credentials as IAuthBearer);
break;
case EAuthTypes.Digest:
this.authDetails = digest(this.credentials);
this.authHeader = digest(this.credentials as IAuthDigest, this.extra as { url: IUrl, method: EHttpMethod });
break;
case EAuthTypes.OAuth1:
this.authDetails = oauth1(this.credentials, this.extra);
this.authHeader = oauth1(this.credentials as IOAuth1, this.extra);
break;
case EAuthTypes.OAuth2:
this.authDetails = await oauth2(this.credentials, this.extra);
this.authHeader = await oauth2(this.credentials as IOAuth2, this.extra);
break;

default:
Expand All @@ -39,11 +42,9 @@ export default class Auth {
}

getHeader(): IAuthHeader | object {
if (this.extra.authType === EAuthTypes.Aws4) {
return { ...this.authDetails };
if (this.authType === EAuthTypes.Aws4) {
return { ...this.aws4AuthHeaders };
} else
return {
Authorization: this.authDetails,
};
return { "Authorization": this.authHeader };
}
}
2 changes: 0 additions & 2 deletions packages/firecamp-rest/src/services/auth/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
EAuthTypes,
EHttpMethod,
IAuthAws4,
IAuthBasic,
Expand All @@ -21,7 +20,6 @@ export interface IExtra {
body?: any;
agent?: EFirecampAgent;
headers?: object;
authType: EAuthTypes;
}

export type TAuth =
Expand Down
8 changes: 3 additions & 5 deletions packages/firecamp-rest/src/services/rest-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,21 +551,19 @@ export const getAuthHeaders = async (
_misc.firecampAgent() === EFirecampAgent.desktop
? EFirecampAgent.desktop
: EFirecampAgent.extension;
let extraParams = {
const extraParams = {
url,
method,
body,
agent,
headers,
authType: authType || meta.active_auth_type,
};

// console.log({ extraParams, requestAuth });

let authServicePayload = requestAuth?.[authType];
let authServicePayload = requestAuth[authType];
// console.log({ authServicePayload });

// debugger;u
// manage OAuth2 payload
if (meta?.active_auth_type === EAuthTypes.OAuth2) {
let oAuth2 = requestAuth[EAuthTypes.OAuth2];
Expand All @@ -574,7 +572,7 @@ export const getAuthHeaders = async (
authServicePayload = activeGrantTypePayload;
}

const authService = new Auth(authServicePayload, extraParams);
const authService = new Auth(authType || meta.active_auth_type, authServicePayload, extraParams);
await authService.authorize();
let authHeaders = await authService.getHeader();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ const AuthSetting: FC<IAuthSetting> = ({
<Notes
type="info"
title="Coming soon!!"
description={`Firecamp Team is building this feature and it’ll be releasing very soon. Keep your eyes open at <span> <a href="https://github.com/firecamp-io/firecamp/releases" target="_blank">
description={`Firecamp team is building this feature and it’ll be releasing very soon. Keep us watching on <span> <a href="https://github.com/firecamp-io/firecamp/releases" target="_blank">
Github </a>, <a href="https://twitter.com/FirecampHQ" target="_blank">Twitter</a>, <a href="https://discord.com/invite/8hRaqhK" target="_blank"> Discord</a> </span>.`}
/>
</div>
Expand Down

0 comments on commit 893db86

Please sign in to comment.