Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cozy_oauth_proxy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
web-et-numerique
Factory
LLLE_Project
cozy_oauth_proxy
Commits
f8fbb744
Commit
f8fbb744
authored
5 years ago
by
Yoan VALLET
Browse files
Options
Downloads
Patches
Plain Diff
Format logs for token endpoint
parent
2d305989
No related branches found
No related tags found
No related merge requests found
Pipeline
#5466
passed
5 years ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.go
+10
-8
10 additions, 8 deletions
main.go
with
10 additions
and
8 deletions
main.go
+
10
−
8
View file @
f8fbb744
...
@@ -112,8 +112,9 @@ func main() {
...
@@ -112,8 +112,9 @@ func main() {
grantType
:=
""
grantType
:=
""
refreshToken
:=
""
refreshToken
:=
""
// For request token params are into query parameters
if
len
(
query
)
==
0
{
if
len
(
query
)
==
0
{
fmt
.
Println
(
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
),
"
No url
params found
- check in the
body"
)
fmt
.
Println
(
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
),
"
- No
params found
in url query - Trying to catch them from
body"
)
contents
,
err
:=
ioutil
.
ReadAll
(
r
.
Body
)
contents
,
err
:=
ioutil
.
ReadAll
(
r
.
Body
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
...
@@ -122,7 +123,7 @@ func main() {
...
@@ -122,7 +123,7 @@ func main() {
//Check for client_id
//Check for client_id
clientIdStartIndex
:=
strings
.
Index
(
pageContent
,
"client_id="
)
clientIdStartIndex
:=
strings
.
Index
(
pageContent
,
"client_id="
)
if
clientIdStartIndex
==
-
1
{
if
clientIdStartIndex
==
-
1
{
fmt
.
Println
(
"
No client_id found"
)
fmt
.
Println
(
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
),
" - Error -
No client_id found"
)
http
.
Error
(
w
,
http
.
StatusText
(
500
),
500
)
http
.
Error
(
w
,
http
.
StatusText
(
500
),
500
)
}
}
clientIdStartIndex
+=
10
clientIdStartIndex
+=
10
...
@@ -130,7 +131,7 @@ func main() {
...
@@ -130,7 +131,7 @@ func main() {
//Check for client_secret
//Check for client_secret
clientSecretStartIndex
:=
strings
.
Index
(
pageContent
,
"client_secret="
)
clientSecretStartIndex
:=
strings
.
Index
(
pageContent
,
"client_secret="
)
if
clientSecretStartIndex
==
-
1
{
if
clientSecretStartIndex
==
-
1
{
fmt
.
Println
(
"
No client_secret found"
)
fmt
.
Println
(
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
),
" - Error -
No client_secret found"
)
http
.
Error
(
w
,
http
.
StatusText
(
500
),
500
)
http
.
Error
(
w
,
http
.
StatusText
(
500
),
500
)
}
}
clientSecretStartIndex
+=
14
clientSecretStartIndex
+=
14
...
@@ -138,7 +139,7 @@ func main() {
...
@@ -138,7 +139,7 @@ func main() {
//Check for code
//Check for code
codeStartIndex
:=
strings
.
Index
(
pageContent
,
"code="
)
codeStartIndex
:=
strings
.
Index
(
pageContent
,
"code="
)
if
codeStartIndex
==
-
1
{
if
codeStartIndex
==
-
1
{
fmt
.
Println
(
"No code found
"
)
fmt
.
Println
(
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
),
" - Info - No code found (optionnal param)
"
)
}
else
{
}
else
{
codeStartIndex
+=
5
codeStartIndex
+=
5
code
=
pageContent
[
codeStartIndex
:
codeStartIndex
+
30
]
code
=
pageContent
[
codeStartIndex
:
codeStartIndex
+
30
]
...
@@ -146,25 +147,27 @@ func main() {
...
@@ -146,25 +147,27 @@ func main() {
//Check for grant_type
//Check for grant_type
grandTypeStartIndex
:=
strings
.
Index
(
pageContent
,
"grant_type="
)
grandTypeStartIndex
:=
strings
.
Index
(
pageContent
,
"grant_type="
)
if
grandTypeStartIndex
==
-
1
{
if
grandTypeStartIndex
==
-
1
{
fmt
.
Println
(
"
No grant_type found"
)
fmt
.
Println
(
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
),
" - Error -
No grant_type found"
)
http
.
Error
(
w
,
http
.
StatusText
(
500
),
500
)
http
.
Error
(
w
,
http
.
StatusText
(
500
),
500
)
}
}
grandTypeStartIndex
+=
11
grandTypeStartIndex
+=
11
tempGrandTypeString
:=
pageContent
[
grandTypeStartIndex
:
len
(
pageContent
)]
tempGrandTypeString
:=
pageContent
[
grandTypeStartIndex
:
len
(
pageContent
)]
grandTypeEndIndex
:=
strings
.
Index
(
tempGrandTypeString
,
"&"
)
grandTypeEndIndex
:=
strings
.
Index
(
tempGrandTypeString
,
"&"
)
if
grandTypeEndIndex
==
-
1
{
if
grandTypeEndIndex
==
-
1
{
fmt
.
Println
(
"
No closing tag for grant_type found"
)
fmt
.
Println
(
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
),
" - Error -
No closing tag for grant_type found"
)
http
.
Error
(
w
,
http
.
StatusText
(
500
),
500
)
http
.
Error
(
w
,
http
.
StatusText
(
500
),
500
)
}
}
grantType
=
tempGrandTypeString
[
0
:
grandTypeEndIndex
]
grantType
=
tempGrandTypeString
[
0
:
grandTypeEndIndex
]
//Check for refresh_token
//Check for refresh_token
refershTokenStartIndex
:=
strings
.
Index
(
pageContent
,
"refresh_token="
)
refershTokenStartIndex
:=
strings
.
Index
(
pageContent
,
"refresh_token="
)
if
refershTokenStartIndex
==
-
1
{
if
refershTokenStartIndex
==
-
1
{
fmt
.
Println
(
"No code found"
)
fmt
.
Println
(
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
),
" - Error - No refresh_token found"
)
http
.
Error
(
w
,
http
.
StatusText
(
500
),
500
)
}
}
refershTokenStartIndex
+=
14
refershTokenStartIndex
+=
14
refreshToken
=
pageContent
[
refershTokenStartIndex
:
refershTokenStartIndex
+
46
]
refreshToken
=
pageContent
[
refershTokenStartIndex
:
refershTokenStartIndex
+
46
]
}
else
{
}
else
{
// Retrieve params from query
clientId
=
query
.
Get
(
"client_id"
)
clientId
=
query
.
Get
(
"client_id"
)
clientSecret
=
query
.
Get
(
"client_secret"
)
clientSecret
=
query
.
Get
(
"client_secret"
)
code
=
query
.
Get
(
"code"
)
code
=
query
.
Get
(
"code"
)
...
@@ -178,7 +181,6 @@ func main() {
...
@@ -178,7 +181,6 @@ func main() {
fmt
.
Printf
(
"grant_type: %s
\n
"
,
grantType
)
fmt
.
Printf
(
"grant_type: %s
\n
"
,
grantType
)
fmt
.
Printf
(
"refresh_token: %s
\n
"
,
refreshToken
)
fmt
.
Printf
(
"refresh_token: %s
\n
"
,
refreshToken
)
tokenUrl
:=
"https://gw.hml.api.enedis.fr/v1/oauth2/token"
tokenUrl
:=
"https://gw.hml.api.enedis.fr/v1/oauth2/token"
data
:=
url
.
Values
{}
data
:=
url
.
Values
{}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment