Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
server
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
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
Show more breadcrumbs
m-team
oidc
mytoken
server
Commits
e931c07f
Verified
Commit
e931c07f
authored
1 year ago
by
Gabriel Zachmann
Browse files
Options
Downloads
Patches
Plain Diff
[guest mode] do not use same subject for all guests
parent
539655a5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
internal/endpoints/guestmode/guestmode.go
+29
-4
29 additions, 4 deletions
internal/endpoints/guestmode/guestmode.go
with
29 additions
and
4 deletions
internal/endpoints/guestmode/guestmode.go
+
29
−
4
View file @
e931c07f
package
guestmode
import
(
"encoding/base64"
"encoding/json"
"github.com/gofiber/fiber/v2"
"github.com/oidc-mytoken/utils/utils"
"github.com/oidc-mytoken/server/internal/config"
"github.com/oidc-mytoken/server/internal/server/paths"
"github.com/oidc-mytoken/server/internal/server/routes"
"github.com/oidc-mytoken/server/internal/utils/hashutils"
)
func
Init
(
s
fiber
.
Router
)
{
...
...
@@ -30,19 +34,40 @@ func handleConfig(ctx *fiber.Ctx) error {
return
ctx
.
JSON
(
conf
)
}
var
stateDB
map
[
string
]
string
func
init
()
{
stateDB
=
make
(
map
[
string
]
string
)
}
func
handleAuth
(
ctx
*
fiber
.
Ctx
)
error
{
state
:=
ctx
.
Query
(
"state"
)
return
ctx
.
Redirect
(
routes
.
RedirectURI
+
"?state="
+
state
+
"&code=code"
)
stateDB
[
state
]
=
ctx
.
IP
()
return
ctx
.
Redirect
(
routes
.
RedirectURI
+
"?state="
+
state
+
"&code="
+
state
)
}
func
handleToken
(
ctx
*
fiber
.
Ctx
)
error
{
var
body
struct
{
StateCode
string
`json:"code" xml:"code" form:"code"`
}
_
=
ctx
.
BodyParser
(
&
body
)
sub
:=
"guest-"
if
body
.
StateCode
!=
""
{
sub
+=
hashutils
.
SHA3_256Str
([]
byte
(
stateDB
[
body
.
StateCode
]))
}
else
{
sub
+=
hashutils
.
SHA3_256Str
([]
byte
(
utils
.
RandASCIIString
(
32
)))
}
data
,
err
:=
json
.
Marshal
(
map
[
string
]
string
{
"sub"
:
sub
})
if
err
!=
nil
{
return
err
}
idToken
:=
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9."
+
base64
.
RawURLEncoding
.
EncodeToString
(
data
)
+
"."
return
ctx
.
JSON
(
map
[
string
]
any
{
"access_token"
:
utils
.
RandASCIIString
(
64
),
"refresh_token"
:
utils
.
RandASCIIString
(
64
),
"id_token"
:
`eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJndWVzdCJ9.
OI5skE5VAlQjI4rqAFUjqwGyEnmmQNXBTOvO7pukZoo`
,
"expires_in"
:
600
,
"id_token"
:
idToken
,
"expires_in"
:
600
,
},
)
}
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