Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Matthieu Christian Emerenciano De Oliveira
LoggiStudy
Commits
33bb1e43
Commit
33bb1e43
authored
Nov 30, 2021
by
Matthieu Christian
Browse files
feat: adds a security dotenv in project
parent
e9939c1b
Changes
5
Hide whitespace changes
Inline
Side-by-side
.env.example
0 → 100644
View file @
33bb1e43
# Configurações do APLICATIVO
APP_EMAIL=
APP_PASSWORD=
# Configurações de USUÁRIO
USER_EMAIL=
USER_PASSWORD=
\ No newline at end of file
package.json
View file @
33bb1e43
...
...
@@ -11,6 +11,7 @@
"license"
:
"
ISC
"
,
"dependencies"
:
{
"
axios
"
:
"
^0.24.0
"
,
"
dotenv
"
:
"
^10.0.0
"
,
"
uuid
"
:
"
^8.3.2
"
}
}
src/poc/gerarInstancia.js
View file @
33bb1e43
import
dotenv
from
'
dotenv
'
;
import
{
v1
}
from
'
uuid
'
;
import
{
api
}
from
'
../api/services/SGEOLConnection.js
'
;
import
{
login
,
userToken
}
from
'
./login.js
'
;
dotenv
.
config
();
const
createAInstance
=
async
(
coordinates
,
type
)
=>
{
const
{
token
,
authorizationCode
}
=
await
login
();
const
{
token
,
authorizationCode
}
=
await
login
(
process
.
env
.
APP_EMAIL
,
process
.
env
.
APP_PASSWORD
);
const
{
access_token
}
=
await
userToken
(
token
,
authorizationCode
);
const
{
access_token
}
=
await
userToken
(
process
.
env
.
USER_EMAIL
,
process
.
env
.
USER_PASSWORD
,
token
,
authorizationCode
);
const
instance
=
{
'
@context
'
:
[
...
...
src/poc/login.js
View file @
33bb1e43
import
{
api
}
from
'
../api/services/SGEOLConnection.js
'
;
export
const
login
=
async
()
=>
{
export
const
login
=
async
(
appEmail
,
password
)
=>
{
try
{
const
{
data
}
=
await
api
.
post
(
'
/security/auth/login/app
'
,
new
URLSearchParams
({
username
:
'
app_devboard@test.com
'
,
password
:
'
1234
'
,
username
:
String
(
appEmail
)
,
password
:
String
(
password
)
,
})
);
return
validadeToken
(
data
.
access_token
);
}
catch
(
error
)
{
console
.
log
(
error
.
data
.
message
);
console
.
log
(
error
);
}
};
...
...
@@ -27,17 +27,22 @@ const validadeToken = async token => {
idApp
:
validate
.
id
,
};
}
catch
(
error
)
{
console
.
log
(
error
.
response
.
data
);
console
.
log
(
error
);
}
};
export
const
userToken
=
async
(
token
,
applicationToken
)
=>
{
export
const
userToken
=
async
(
userEmail
,
password
,
token
,
applicationToken
)
=>
{
try
{
const
{
data
:
user
}
=
await
api
.
post
(
`/security/auth/login/user`
,
new
URLSearchParams
({
username
:
'
manager@example.com
'
,
password
:
'
1234
'
,
username
:
String
(
userEmail
)
,
password
:
String
(
password
)
,
'
application-token
'
:
token
,
}),
{
...
...
@@ -50,7 +55,7 @@ export const userToken = async (token, applicationToken) => {
return
user
;
}
catch
(
err
)
{
console
.
log
(
err
.
request
.
data
);
console
.
log
(
err
);
}
};
...
...
yarn.lock
View file @
33bb1e43
...
...
@@ -9,6 +9,11 @@ axios@^0.24.0:
dependencies:
follow-redirects "^1.14.4"
dotenv@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==
follow-redirects@^1.14.4:
version "1.14.5"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.5.tgz#f09a5848981d3c772b5392309778523f8d85c381"
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment