Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,4 @@ GOOGLE_REDIRECT_URI=http://localhost:3030/oidc/callback/youtube

TWITTER_CLIENT_ID=xxxxxxxxxxxxxxxxxxxxxxxx
TWITTER_CLIENT_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
TWITTER_REDIRECT_URI=http://localhost:3030/oidc/callback/twitter

SPOTIFY_CLIENT_ID=xxxxxxxxxxxxxxxxxxxxxxxx
SPOTIFY_CLIENT_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SPOTIFY_REDIRECT_URI=http://localhost:3030/oidc/callback/spotify
TWITTER_REDIRECT_URI=http://localhost:3030/oidc/callback/twitter
10 changes: 0 additions & 10 deletions src/controllers/account/account.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import { getTwitterFollow } from './twitter/getFollow.action';
import { getYoutube } from './google/get.controller';
import { getYoutubeLike } from './google/youtube/like/get.controller';
import { getYoutubeSubscribe } from './google/youtube/subscribe/get.controller';
import { getSpotifyUserFollow, getSpotifyPlaylistFollow } from './spotify/get.follow.action';
import { getSpotifyTrackPlaying, getSpotifyTrackRecent, getSpotifyTrackSaved } from './spotify/get.track.action';
import { getSpotify } from './spotify/get.action';
import { createLoginValidation, postLogin } from './login/post.controller';

const router = express.Router();
Expand All @@ -33,13 +30,6 @@ router.get('/:sub/google/youtube', guard.check(['account:read']), getYoutube);
router.get('/:sub/google/youtube/like/:item', guard.check(['account:read']), getYoutubeLike);
router.get('/:sub/google/youtube/subscribe/:item', guard.check(['account:read']), getYoutubeSubscribe);

router.get('/:sub/spotify', guard.check(['account:read']), getSpotify);
router.get('/:sub/spotify/user_follow/:item', guard.check(['account:read']), getSpotifyUserFollow);
router.get('/:sub/spotify/playlist_follow/:item', guard.check(['account:read']), getSpotifyPlaylistFollow);
router.get('/:sub/spotify/track_playing/:item', guard.check(['account:read']), getSpotifyTrackPlaying);
router.get('/:sub/spotify/track_recent/:item', guard.check(['account:read']), getSpotifyTrackRecent);
router.get('/:sub/spotify/track_saved/:item', guard.check(['account:read']), getSpotifyTrackSaved);

router.get('/address/:address', guard.check(['account:read']), validate([]), getAccountByAddress);
router.get('/email/:email', guard.check(['account:read']), validate([]), getAccountByEmail);
router.patch('/:id', guard.check(['account:read', 'account:write']), patchAccount);
Expand Down
39 changes: 1 addition & 38 deletions src/controllers/account/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import db from '../../util/database';
import { AccountService } from '../../services/AccountService';
import { INITIAL_ACCESS_TOKEN } from '../../util/secrets';
import { accountAddress, accountEmail, accountSecret } from '../../util/jest';
import { SPOTIFY_API_ENDPOINT, TWITTER_API_ENDPOINT } from '../../util/secrets';
import { TWITTER_API_ENDPOINT } from '../../util/secrets';

const http = request.agent(app);

Expand Down Expand Up @@ -135,10 +135,6 @@ describe('Account Controller', () => {

describe('GET /account/:sub/twitter', () => {
beforeAll(async () => {
nock(SPOTIFY_API_ENDPOINT)
.persist()
.get(/.*?/)
.reply(200, { data: { items: [] } });
nock(TWITTER_API_ENDPOINT)
.persist()
.get(/.*?/)
Expand Down Expand Up @@ -209,37 +205,4 @@ describe('Account Controller', () => {
expect(res.body.isAuthorized).toEqual(true);
});
});

describe('GET /account/:sub/spotify', () => {
it('Denice Access if there no authorization header', async () => {
const res = await http.get(`/account/${accountId}/spotify`).send();
expect(res.status).toEqual(401);
});

it('Throw Error if there no linked spotify', async () => {
const res = await http
.get(`/account/${accountId}/spotify`)
.set({
Authorization: authHeader,
})
.send();
expect(res.body.isAuthorized).toEqual(false);
});

it('Successfully get linked Spotify info with a correct infomation', async () => {
const account = await AccountService.getByEmail(accountEmail);
account.spotifyAccessToken = 'TOKEN';
account.spotifyRefreshToken = 'REFRESH';
account.spotifyAccessTokenExpires = (Date.now() + 1000000) * 1000;
await account.save();

const res = await http
.get(`/account/${accountId}/spotify`)
.set({
Authorization: authHeader,
})
.send();
expect(res.body.isAuthorized).toEqual(true);
});
});
});
1 change: 0 additions & 1 deletion src/controllers/account/get.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function formatAccountRes(account: any) {
email: account.email,
googleAccess: account.googleAccessToken && account.googleAccessTokenExpires > Date.now(),
twitterAccess: account.twitterAccessToken && account.twitterAccessTokenExpires > Date.now(),
spotifyAccess: account.spotifyAccessToken && account.spotifyAccessTokenExpires > Date.now(),
},
...protectedPrivateKey,
};
Expand Down
1 change: 0 additions & 1 deletion src/controllers/account/patch.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const patchAccount = async (req: Request, res: Response) => {
address: req.body.address,
googleAccess: req.body.googleAccess,
twitterAccess: req.body.twitterAccess,
spotifyAccess: req.body.spotifyAccess,
authenticationToken: req.body.authenticationToken,
authenticationTokenExpires: req.body.authenticationTokenExpires,
plan: req.body.plan,
Expand Down
37 changes: 0 additions & 37 deletions src/controllers/account/spotify/get.action.ts

This file was deleted.

24 changes: 0 additions & 24 deletions src/controllers/account/spotify/get.follow.action.ts

This file was deleted.

24 changes: 0 additions & 24 deletions src/controllers/account/spotify/get.track.action.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/controllers/oidc/account/get.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Request, Response } from 'express';
import { SpotifyService } from '../../../services/SpotifyService';
import { TwitterService } from '../../../services/TwitterService';
import { YouTubeService } from '../../../services/YouTubeService';
import { AccountService } from '../../../services/AccountService';
Expand All @@ -10,7 +9,6 @@ async function controller(req: Request, res: Response) {

params.googleLoginUrl = YouTubeService.getLoginUrl(req.params.uid, YouTubeService.getBasicScopes());
params.twitterLoginUrl = TwitterService.getLoginURL(uid, {});
params.spotifyLoginUrl = SpotifyService.getLoginURL(uid, {});

return res.render('account', {
uid,
Expand All @@ -27,7 +25,6 @@ async function controller(req: Request, res: Response) {
otpSecret: account.otpSecret,
googleAccess: account.googleAccessToken && account.googleAccessTokenExpires > Date.now(),
twitterAccess: account.twitterAccessToken && account.twitterAccessTokenExpires > Date.now(),
spotifyAccess: account.spotifyAccessToken && account.spotifyAccessTokenExpires > Date.now(),
},
});
}
Expand Down
15 changes: 0 additions & 15 deletions src/controllers/oidc/account/spotify/disconnect/post.controller.ts

This file was deleted.

58 changes: 0 additions & 58 deletions src/controllers/oidc/callback/spotify/get.controller.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/controllers/oidc/connect/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Request, Response } from 'express';
import { oidc } from '../../../util/oidc';
import { ChannelType } from '../../../models/Reward';
import { AccountService } from '../../../services/AccountService';
import { SpotifyService } from '../../../services/SpotifyService';
import { TwitterService } from '../../../services/TwitterService';
import { YouTubeService } from '../../../services/YouTubeService';

Expand All @@ -23,8 +22,6 @@ async function controller(req: Request, res: Response) {
}
} else if (params.channel == ChannelType.Twitter && !account.twitterAccessToken) {
redirect = TwitterService.getLoginURL(uid, {});
} else if (params.channel == ChannelType.Spotify && !account.spotifyAccessToken) {
redirect = SpotifyService.getLoginURL(uid, {});
}

if (!redirect) {
Expand Down
9 changes: 0 additions & 9 deletions src/controllers/oidc/oidc.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,19 @@ import CreateForgot from './forgot/post';
import CreateReset from './reset/post';
import ReadCallbackGoogle from './callback/google/get.controller';
import ReadCallbackTwitter from './callback/twitter/get.controller';
import ReadCallbackSpotify from './callback/spotify/get.controller';
import ReadAccount from './account/get';
import UpdateAccount from './account/post';
import UpdateAccountTOTP from './account/totp/post';
import ReadAccountTOTP from './account/totp/get';
import PostGoogleDisconnect from './account/google/disconnect/post.controller';
import PostTwitterDisconnect from './account/twitter/disconnect/post.controller';
import PostSpotifyDisconnect from './account/spotify/disconnect/post.controller';
import ReadAccountEmailVerify from './account/email/get';
import { assertInput, assertAuthorization, assertInteraction } from '../../middlewares';

const router = express.Router();

router.get('/callback/google', ReadCallbackGoogle.controller);
router.get('/callback/twitter', ReadCallbackTwitter.controller);
router.get('/callback/spotify', ReadCallbackSpotify.controller);

// Routes require no auth
router.get('/:uid', assertInteraction, ReadOIDC.controller);
Expand All @@ -57,12 +54,6 @@ router.get('/:uid/connect', assertInteraction, assertAuthorization, ReadConnect.
router.get('/:uid/account', assertInteraction, assertAuthorization, ReadAccount.controller);

router.post('/:uid/account/google/disconnect', assertInteraction, assertAuthorization, PostGoogleDisconnect.controller);
router.post(
'/:uid/account/spotify/disconnect',
assertInteraction,
assertAuthorization,
PostSpotifyDisconnect.controller,
);
router.post(
'/:uid/account/twitter/disconnect',
assertInteraction,
Expand Down
2 changes: 0 additions & 2 deletions src/controllers/oidc/signin/get.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Request, Response } from 'express';
import { AUTH_URL, WALLET_URL } from '../../../util/secrets';
import { SpotifyService } from '../../../services/SpotifyService';
import { TwitterService } from '../../../services/TwitterService';
import { YouTubeService } from '../../../services/YouTubeService';
import { AUTH_REQUEST_TYPED_MESSAGE, createTypedMessage } from '../../../util/typedMessage';
Expand All @@ -11,7 +10,6 @@ async function controller(req: Request, res: Response) {

if (params.return_url === WALLET_URL) {
params.twitterLoginUrl = TwitterService.getLoginURL(uid, {});
params.spotifyLoginUrl = SpotifyService.getLoginURL(uid, {});
params.authRequestMessage = createTypedMessage(AUTH_REQUEST_TYPED_MESSAGE, AUTH_URL, uid);
}
res.render('signin', { uid, params, alert: {} });
Expand Down
Loading