Skip to content

Commit

Permalink
random packageの関数を使う
Browse files Browse the repository at this point in the history
  • Loading branch information
pirosiki197 committed Dec 23, 2024
1 parent 3d0d049 commit ee46863
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions server/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/traPtitech/piscon-portal-v2/server/handler"
"github.com/traPtitech/piscon-portal-v2/server/repository"
"github.com/traPtitech/piscon-portal-v2/server/services/oauth2"
"github.com/traPtitech/piscon-portal-v2/server/utils/random"
)

const Oauth2ServerURL = "http://localhost:9000"
Expand Down Expand Up @@ -159,7 +160,7 @@ func (s *oauth2Server) handleAuthorize(w http.ResponseWriter, r *http.Request) {
codeChallenge := q.Get("code_challenge")
state := q.Get("state")

code := randomString()
code := random.String(32)

s.codeChallengeMap.Set(code, codeChallenge, 15*time.Minute)
// use user params as username for testing
Expand Down Expand Up @@ -257,9 +258,3 @@ func (s *oauth2Server) handleJWKS(w http.ResponseWriter, _ *http.Request) {
},
})
}

func randomString() string {
b := make([]byte, 32)
rand.Read(b)
return base64.RawURLEncoding.EncodeToString(b)
}

0 comments on commit ee46863

Please sign in to comment.