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
2d305989
Commit
2d305989
authored
5 years ago
by
Yoan VALLET
Browse files
Options
Downloads
Patches
Plain Diff
Retrieve information from body for refresh token
parent
49a4da07
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#5465
passed
5 years ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.go
+73
-12
73 additions, 12 deletions
main.go
with
73 additions
and
12 deletions
main.go
+
73
−
12
View file @
2d305989
...
...
@@ -90,8 +90,8 @@ func main() {
if
splitIndex
==
-
1
{
fmt
.
Println
(
"No host found"
)
}
state
:=
string
([]
byte
(
req_state
[
0
:
splitIndex
]
))
host
:=
string
([]
byte
(
req_state
[
splitIndex
+
1
:
len
(
req_state
)]
))
state
:=
req_state
[
0
:
splitIndex
]
host
:=
req_state
[
splitIndex
+
1
:
len
(
req_state
)]
usagePointId
:=
query
.
Get
(
"usage_point_id"
)
...
...
@@ -106,17 +106,78 @@ func main() {
query
:=
r
.
URL
.
Query
()
fmt
.
Println
(
query
)
c
ontents
,
err
:=
ioutil
.
ReadAll
(
r
.
Body
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
fmt
.
Println
(
string
(
contents
))
c
lientId
:=
""
clientSecret
:=
""
code
:=
""
grantType
:=
""
refreshToken
:=
""
clientId
:=
query
.
Get
(
"client_id"
)
clientSecret
:=
query
.
Get
(
"client_secret"
)
code
:=
query
.
Get
(
"code"
)
grantType
:=
query
.
Get
(
"grant_type"
)
refreshToken
:=
query
.
Get
(
"refresh_token"
)
if
len
(
query
)
==
0
{
fmt
.
Println
(
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
),
"No url params found - check in the body"
)
contents
,
err
:=
ioutil
.
ReadAll
(
r
.
Body
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
pageContent
:=
string
(
contents
)
//Check for client_id
clientIdStartIndex
:=
strings
.
Index
(
pageContent
,
"client_id="
)
if
clientIdStartIndex
==
-
1
{
fmt
.
Println
(
"No client_id found"
)
http
.
Error
(
w
,
http
.
StatusText
(
500
),
500
)
}
clientIdStartIndex
+=
10
clientId
=
pageContent
[
clientIdStartIndex
:
clientIdStartIndex
+
36
]
//Check for client_secret
clientSecretStartIndex
:=
strings
.
Index
(
pageContent
,
"client_secret="
)
if
clientSecretStartIndex
==
-
1
{
fmt
.
Println
(
"No client_secret found"
)
http
.
Error
(
w
,
http
.
StatusText
(
500
),
500
)
}
clientSecretStartIndex
+=
14
clientSecret
=
pageContent
[
clientSecretStartIndex
:
clientSecretStartIndex
+
36
]
//Check for code
codeStartIndex
:=
strings
.
Index
(
pageContent
,
"code="
)
if
codeStartIndex
==
-
1
{
fmt
.
Println
(
"No code found"
)
}
else
{
codeStartIndex
+=
5
code
=
pageContent
[
codeStartIndex
:
codeStartIndex
+
30
]
}
//Check for grant_type
grandTypeStartIndex
:=
strings
.
Index
(
pageContent
,
"grant_type="
)
if
grandTypeStartIndex
==
-
1
{
fmt
.
Println
(
"No grant_type found"
)
http
.
Error
(
w
,
http
.
StatusText
(
500
),
500
)
}
grandTypeStartIndex
+=
11
tempGrandTypeString
:=
pageContent
[
grandTypeStartIndex
:
len
(
pageContent
)]
grandTypeEndIndex
:=
strings
.
Index
(
tempGrandTypeString
,
"&"
)
if
grandTypeEndIndex
==
-
1
{
fmt
.
Println
(
"No closing tag for grant_type found"
)
http
.
Error
(
w
,
http
.
StatusText
(
500
),
500
)
}
grantType
=
tempGrandTypeString
[
0
:
grandTypeEndIndex
]
//Check for refresh_token
refershTokenStartIndex
:=
strings
.
Index
(
pageContent
,
"refresh_token="
)
if
refershTokenStartIndex
==
-
1
{
fmt
.
Println
(
"No code found"
)
}
refershTokenStartIndex
+=
14
refreshToken
=
pageContent
[
refershTokenStartIndex
:
refershTokenStartIndex
+
46
]
}
else
{
clientId
=
query
.
Get
(
"client_id"
)
clientSecret
=
query
.
Get
(
"client_secret"
)
code
=
query
.
Get
(
"code"
)
grantType
=
query
.
Get
(
"grant_type"
)
refreshToken
=
query
.
Get
(
"refresh_token"
)
}
// Print out the result
fmt
.
Printf
(
"client_id: %s
\n
"
,
clientId
)
fmt
.
Printf
(
"client_secret: %s
\n
"
,
clientSecret
)
fmt
.
Printf
(
"code: %s
\n
"
,
code
)
fmt
.
Printf
(
"grant_type: %s
\n
"
,
grantType
)
fmt
.
Printf
(
"refresh_token: %s
\n
"
,
refreshToken
)
tokenUrl
:=
"https://gw.hml.api.enedis.fr/v1/oauth2/token"
...
...
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