-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement authentication and user modules #9
Open
Sasha-belokur
wants to merge
123
commits into
master
Choose a base branch
from
user/profile
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
123 commits
Select commit
Hold shift + click to select a range
5e44c4d
Change versions of welcom module
Iwasherd 622a533
Merge branch 'master' of https://github.com/sysgears/restapp
Iwasherd f020440
Create request middleware
Iwasherd fcba3ef
Add locales
Iwasherd e65edd9
Add auth base components
Iwasherd 907aad7
Add Data root component
Iwasherd 84ed707
Add config
Iwasherd 236aff7
Add universalcoockie interface
Iwasherd 4393437
Add register functionality with reducers
Iwasherd e404dda
Add register functionality for mobile app
Iwasherd 0f369c2
Update ServerModule
Sasha-belokur c5993f4
Add initial setup for server user module
Sasha-belokur 96a444c
Update createServerApp
Sasha-belokur 83185c7
Add emailTemplate
Sasha-belokur 05e59c7
Add password sub-module
Sasha-belokur 90c5115
Add bodyParser for app
Sasha-belokur 2d62b17
Merge branch 'user/sign-up' of github.com:sysgears/restapp into user/…
Sasha-belokur d2f2a5f
Change form error handler
Iwasherd 1b119b3
Merge branch 'user/sign-up' of github.com:sysgears/restapp into user/…
Sasha-belokur 79cea34
Add status for errors response in register
Sasha-belokur 1cd7ed2
Fix typo in migrations
Sasha-belokur 65e6ab8
Fix redux middleware
Iwasherd c96ad9d
Merge branch 'user/sign-up' of https://github.com/sysgears/restapp in…
Iwasherd be7ded2
Add auth module
Sasha-belokur 5ed25af
Add types for passport
Sasha-belokur 72b4ba9
Add config for session and jwt
Sasha-belokur dfda04a
Add login conrtoller
Sasha-belokur 08e2d22
Fix validation errors
Iwasherd a7e0c7d
Remove social auth
Sasha-belokur acc851e
Update types for auth module
Sasha-belokur 54a24a0
Merge branch 'user/sign-up' into user/sign-up-and-login
Iwasherd 24b0845
Update LocalStrategy usernameField
Sasha-belokur 9438b34
Update errors response
Sasha-belokur b76267c
Merge branch 'user/sign-up' of github.com:sysgears/restapp into user/…
Sasha-belokur 9f9dba8
Merge branch 'user/sign-up' into user/sign-up-and-login
Iwasherd 66cbb63
Merge branch 'user/sign-up-and-login' of https://github.com/sysgears/…
Iwasherd 71645c1
Add uthentication module
Iwasherd 4453d8c
Add httpClient in Client module and create request handler
Iwasherd e012105
Add login and logout components
Iwasherd 8abe1f6
Add authentication to modules
Sasha-belokur 2575223
Add controller for current user
Sasha-belokur 45fd75f
Fix handle response
Iwasherd 2ec0ad9
Merge branch 'user/sign-up-and-login' of https://github.com/sysgears/…
Iwasherd 231245b
Add loading component and Fix login with logout
Iwasherd e6d1d91
Create react-native redux middleware
Iwasherd b66bfe2
Add react-native login
Iwasherd 9734284
Update errors response in login
Sasha-belokur 6de1a0e
Add response for session logout
Sasha-belokur 866b83f
Merge branch 'user/sign-up-and-login' of github.com:sysgears/restapp …
Sasha-belokur 92a089e
Fix throw
Iwasherd 93ee909
Merge branch 'user/sign-up-and-login' of https://github.com/sysgears/…
Iwasherd 7f6d886
Add controllers for profile
Sasha-belokur 8d867e1
Move redux middleware in authentication jwt module and add requests f…
Iwasherd eded36d
Update controllers
Sasha-belokur d720d5d
Merge branch 'user/profile' of github.com:sysgears/restapp into user/…
Sasha-belokur 7f69b5c
Rename redux middleware
Iwasherd 4bb5ebb
Fix get users and users filters
Iwasherd d9b694e
Remove extra property in user conrtoller
Sasha-belokur da85106
Merge branch 'user/profile' of github.com:sysgears/restapp into user/…
Sasha-belokur be5a69e
Fix add and edit user
Iwasherd 454c129
Fix react-native user interface
Iwasherd 9591392
Add try catch for form validations
Iwasherd 2cbb167
Add check for accessMiddleware
Sasha-belokur 658c71c
Add forgot and reset password conrtollers
Sasha-belokur 42970ec
Moved passport loging middleware to auth module
Sasha-belokur 6243240
Merge branch 'user/profile' of github.com:sysgears/restapp into user/…
Sasha-belokur 7e85182
Update session accessMiddleware response
Sasha-belokur aedd4fa
Add common redux middleware for async operation and middleware in jwt…
Iwasherd 5b16e3f
removed extra features
Iwasherd 4e6c08f
Reaname callAPI to APICall
Iwasherd f58a58e
Fix prew commit
Iwasherd a099c75
Update controllers with identity check
Sasha-belokur b3ec2b1
Remove table auth_certificate from migrations
Sasha-belokur 8095418
Fix typo in user conrtollers
Sasha-belokur c63245b
Add reset and forgot password components
Iwasherd d43956b
Add routes and navigations screens for forgot and reset password
Iwasherd 3f21abd
Add social to user and auth modules
Sasha-belokur 5bf50f0
Merge branch 'user/profile' of github.com:sysgears/restapp into user/…
Sasha-belokur ff7e86d
Fix invalid refresh token response
Sasha-belokur db05f63
Divide the storage into several
Iwasherd 9a38a0d
Clear data
Iwasherd 886b611
Add request on currentUser in AuthRoute
Iwasherd 30cb626
Implement working socils with jwt module
Iwasherd d227a1e
Fix social auth with jwt
Iwasherd 7cb9828
Fix socials with session
Iwasherd dd6a25c
Clear data
Iwasherd 8e91567
Change interfaces
Iwasherd 38be3a8
Move session settings to settings module
Iwasherd f568b2d
Fix check on empty tokens
Iwasherd 84db025
Add interface for user action creators
Iwasherd fb53859
Add and Fix Profile on react-native app
Iwasherd 6850d25
Fix login valiadtion errors in Login component
Iwasherd 3cf8827
Change api url
Iwasherd 7bea2fc
Fix Set redux store data after 401 response
Iwasherd b4549c3
Fix reset pass when editing user
Iwasherd 5235f6c
Remove InputItem from server module
Iwasherd 585d3b3
Fix check on empty tokens
Iwasherd 32eab84
Fix UserShapePassword interface
Iwasherd f2cbfb0
Clear unnecessary try catch
Iwasherd 3d0d1d3
Re-write UserEdit component on functional component
Iwasherd 0e70bfe
Fix sending 401 status
Iwasherd 0f64679
Merge branch 'master' of https://github.com/sysgears/restapp
Iwasherd 160b198
Merge with master and fixing some mistakes
Iwasherd e0028d0
Fix redirect from auth routes
Iwasherd 8c6c0d9
Separation of a user module into signUp, profile and users modules
Iwasherd 701b2a6
Create MetaData component
Iwasherd b41a755
Move common types in types directory
Iwasherd a20423e
Fix prev commit
Iwasherd 7615835
Cleanup
gekanchiko d5a9c21
Rename action functions
Iwasherd 12c1486
Merge branch 'master' of https://github.com/sysgears/restapp
Iwasherd e0a0d55
Merge with master
Iwasherd 83f442b
Fix prew commit
Iwasherd e964240
Move MetaData to look module
Iwasherd 916beb1
Revert "Fix prew commit"
Iwasherd 5a6b803
Update yarn lock
Iwasherd 40560ba
Fix yarn.lock
Iwasherd 308f1c2
Add confirmation api route
basilalex 5cdd618
Update confirmation link
basilalex 1852195
Fix type of isActive argument
basilalex d362d22
Clear env
basilalex 0dcb21a
Fix forgotPassword controller
basilalex 709291e
Fix broken link
basilalex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ jsconfig.json | |
public | ||
*.iml | ||
.npmrc | ||
packages/server/sessions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
export default { | ||
secret: process.env.NODE_ENV === 'test' ? 'secret for tests' : process.env.AUTH_SECRET, | ||
session: { | ||
enabled: false, | ||
secret: 'secret', | ||
store: null, | ||
cookie: { maxAge: 60000 }, | ||
resave: false, | ||
saveUninitialized: false | ||
}, | ||
jwt: { | ||
enabled: true, | ||
tokenExpiresIn: '1m', | ||
refreshTokenExpiresIn: '7d' | ||
}, | ||
password: { | ||
requireEmailConfirmation: true, | ||
sendPasswordChangesEmail: true, | ||
minLength: 8, | ||
enabled: true | ||
}, | ||
social: { | ||
facebook: { | ||
enabled: false, | ||
clientID: process.env.FACEBOOK_CLIENTID, | ||
clientSecret: process.env.FACEBOOK_CLIENTSECRET, | ||
callbackURL: '/api/auth/facebook/callback', | ||
scope: ['email'], | ||
profileFields: ['id', 'emails', 'displayName'] | ||
}, | ||
github: { | ||
enabled: false, | ||
clientID: process.env.GITHUB_CLIENTID, | ||
clientSecret: process.env.GITHUB_CLIENTSECRET, | ||
callbackURL: '/api/auth/github/callback', | ||
scope: ['user:email'] | ||
}, | ||
linkedin: { | ||
enabled: false, | ||
clientID: process.env.LINKEDIN_CLIENTID, | ||
clientSecret: process.env.LINKEDIN_CLIENTSECRET, | ||
callbackURL: '/api/auth/linkedin/callback', | ||
scope: ['r_liteprofile'] | ||
}, | ||
google: { | ||
enabled: false, | ||
clientID: process.env.GOOGLE_CLIENTID, | ||
clientSecret: process.env.GOOGLE_CLIENTSECRET, | ||
callbackURL: '/api/auth/google/callback', | ||
scope: ['https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile'] | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
modules/authentication/client-react/access/AccessModule.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import ClientModule, { ClientModuleShape } from '@restapp/module-client-react'; | ||
|
||
/** | ||
* Access module which provides authentication functions | ||
*/ | ||
export interface AccessModuleShape extends ClientModuleShape { | ||
// login handlers from all authentication modules | ||
login?: Array<(callback?: () => void) => Promise<void>>; | ||
// logout handlers from all authentication modules | ||
logout?: Array<(callback?: () => void) => Promise<void>>; | ||
} | ||
|
||
interface AccessModule extends AccessModuleShape {} | ||
|
||
class AccessModule extends ClientModule { | ||
/** | ||
* Constructs access module representation, that folds all the feature modules | ||
* into a single module represented by this instance. | ||
* | ||
* @param modules feature modules | ||
*/ | ||
constructor(...modules: AccessModuleShape[]) { | ||
super(...modules); | ||
} | ||
|
||
/** | ||
* call all methods of login in authentication modules. | ||
* | ||
* @returns merge login methods | ||
*/ | ||
public async doLogin(callback?: () => void) { | ||
for (const login of this.login) { | ||
await login(callback); | ||
} | ||
} | ||
|
||
/** | ||
* call all methods of logout in authentication modules. | ||
* | ||
* @returns merge logout methods | ||
*/ | ||
public async doLogout(callback?: () => void) { | ||
for (const logout of this.logout) { | ||
await logout(callback); | ||
} | ||
} | ||
} | ||
|
||
export default AccessModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import * as React from 'react'; | ||
import jwt from './jwt'; | ||
import session from './session'; | ||
import AccessModule from './AccessModule'; | ||
|
||
interface PageReloaderProps { | ||
children?: React.ReactElement; | ||
} | ||
|
||
interface AuthPageReloaderProps extends PageReloaderProps {} | ||
|
||
const ref: React.RefObject<any> = React.createRef(); | ||
|
||
const rerenderApp = () => { | ||
ref.current.reloadPage(); | ||
}; | ||
|
||
const login = async (_clearStore?: () => void) => { | ||
rerenderApp(); | ||
}; | ||
|
||
const logout = async (clearStore: () => void) => { | ||
await clearStore(); | ||
rerenderApp(); | ||
}; | ||
|
||
class PageReloader extends React.Component<PageReloaderProps> { | ||
public state = { | ||
key: 1 | ||
}; | ||
|
||
public reloadPage() { | ||
this.setState({ key: this.state.key + 1 }); | ||
} | ||
|
||
public render() { | ||
return React.cloneElement(this.props.children, { key: this.state.key }); | ||
} | ||
} | ||
|
||
const AuthPageReloader = ({ children }: AuthPageReloaderProps) => <PageReloader ref={ref}>{children}</PageReloader>; | ||
|
||
export default new AccessModule(jwt, session, { | ||
dataRootComponent: [AuthPageReloader], | ||
login: [login], | ||
logout: [logout] | ||
}); |
100 changes: 100 additions & 0 deletions
100
modules/authentication/client-react/access/jwt/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import axios from 'axios'; | ||
import { getItem, setItem, removeItem } from '@restapp/core-common/clientStorage'; | ||
import { Middleware } from 'redux'; | ||
import settings from '../../../../../settings'; | ||
import AccessModule from '../AccessModule'; | ||
|
||
enum TokensEnum { | ||
accessToken = 'accessToken', | ||
refreshToken = 'refreshToken' | ||
} | ||
|
||
interface Tokens { | ||
[key: string]: TokensEnum; | ||
} | ||
|
||
const saveTokens = async ({ accessToken, refreshToken }: Tokens) => { | ||
await setItem(TokensEnum.accessToken, accessToken); | ||
await setItem(TokensEnum.refreshToken, refreshToken); | ||
}; | ||
|
||
const removeTokens = async () => { | ||
await removeItem(TokensEnum.accessToken); | ||
await removeItem(TokensEnum.refreshToken); | ||
}; | ||
|
||
const refreshAccessToken = async () => { | ||
try { | ||
const { data } = await axios.post(`${__API_URL__}/refreshToken`, { | ||
refreshToken: await getItem('refreshToken') | ||
}); | ||
if (data) { | ||
const { accessToken, refreshToken } = data; | ||
await saveTokens({ accessToken, refreshToken }); | ||
} else { | ||
await removeTokens(); | ||
} | ||
} catch (e) { | ||
await removeTokens(); | ||
throw e; | ||
} | ||
}; | ||
|
||
const reduxMiddleware: Middleware = ({ dispatch }) => next => action => { | ||
const { types, status, ...rest } = action; | ||
(async () => { | ||
try { | ||
if (status === 401) { | ||
try { | ||
await refreshAccessToken(); | ||
const newAction = { ...action, status: null }; | ||
return dispatch(newAction); | ||
} catch (e) { | ||
throw e; | ||
} | ||
} | ||
return next(action); | ||
} catch (e) { | ||
next({ | ||
type: types.FAIL, | ||
...rest | ||
}); | ||
throw e; | ||
} | ||
})(); | ||
}; | ||
|
||
axios.interceptors.request.use(async config => { | ||
const accessToken = await getItem(TokensEnum.accessToken); | ||
|
||
const arrayExceptions = ['login', 'refreshTokens']; | ||
const checkInclude = arrayExceptions.some(exception => config.url.includes(exception)); | ||
|
||
config.headers = !checkInclude && accessToken ? { Authorization: `Bearer ${accessToken}` } : {}; | ||
return config; | ||
}); | ||
|
||
axios.interceptors.response.use(async (res: any) => { | ||
if (res.config.url.includes('login')) { | ||
if (!!res.data && res.data.tokens) { | ||
const { | ||
data: { | ||
tokens: { accessToken, refreshToken } | ||
} | ||
} = res; | ||
await saveTokens({ accessToken, refreshToken }); | ||
res.data = res.data.user; | ||
return res; | ||
} else { | ||
await removeTokens(); | ||
} | ||
} | ||
return res; | ||
}); | ||
|
||
export default (settings.auth.jwt.enabled | ||
? new AccessModule({ | ||
logout: [removeTokens], | ||
reduxMiddleware: [reduxMiddleware] | ||
}) | ||
: undefined); |
12 changes: 12 additions & 0 deletions
12
modules/authentication/client-react/access/session/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import settings from '../../../../../settings'; | ||
import AccessModule from '../AccessModule'; | ||
import axios from 'axios'; | ||
|
||
const logout = async () => { | ||
axios.post(`${__API_URL__}/logout`); | ||
}; | ||
export default (settings.auth.session.enabled | ||
? new AccessModule({ | ||
logout: [logout] | ||
}) | ||
: undefined); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import url from 'url'; | ||
import { Constants } from 'expo'; | ||
|
||
export default function buildRedirectUrlForMobile(authType: string) { | ||
const { protocol, hostname, port } = url.parse(__WEBSITE_URL__); | ||
const expoHostname = `${url.parse(Constants.linkingUri).hostname}.nip.io`; | ||
const urlHostname = process.env.NODE_ENV === 'production' ? hostname : expoHostname; | ||
|
||
return `${protocol}//${urlHostname}${port ? ':' + port : ''}/api/auth/${authType}?expoUrl=${encodeURIComponent( | ||
Constants.linkingUri | ||
)}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import authentication from './access'; | ||
|
||
export * from './social'; | ||
|
||
export default authentication; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@restapp/authentication-client-react", | ||
"version": "0.1.0", | ||
"private": true, | ||
"dependencies": { | ||
"@restapp/core-common": "^0.1.0" | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
modules/authentication/client-react/social/facebook/containers/FacebookButton.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
.facebookBtn { | ||
min-width: 320px; | ||
margin-top: 10px; | ||
background-color: #3769ae; | ||
border-color: #3769ae; | ||
display: flex; | ||
justify-content: flex-start; | ||
align-items: center; | ||
} | ||
|
||
.facebookBtn:hover { | ||
background-color: #17427e; | ||
border-color: #17427e; | ||
} | ||
|
||
.iconContainer { | ||
display: flex; | ||
flex: 1 1 10%; | ||
justify-content: flex-start; | ||
align-items: center; | ||
} | ||
|
||
.separator { | ||
height: 28px; | ||
width: 1px; | ||
background-color: #fff !important; | ||
margin-left: 10px; | ||
} | ||
|
||
.btnText { | ||
display: flex; | ||
justify-content: flex-start; | ||
flex: 5 | ||
} | ||
|
||
.facebookIcon { | ||
color: #fff; | ||
font-size: 30px; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should stop using
class
-based components in favor of functional ones.