...

Source file src/github.com/palantir/go-githubapp/oauth2/state.go

Documentation: github.com/palantir/go-githubapp/oauth2

     1  // Copyright 2018 Palantir Technologies, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package oauth2
    16  
    17  import (
    18  	"net/http"
    19  )
    20  
    21  // StateStore generates and verifies the state parameter for OAuth2 flows.
    22  type StateStore interface {
    23  	// GenerateState creates a new state value, storing it in a way that can be
    24  	// retrieved by VerifyState at a later point.
    25  	GenerateState(w http.ResponseWriter, r *http.Request) (string, error)
    26  
    27  	// VerifyState checks that the state associated with the request matches
    28  	// the given state. To avoid timing attacks, implementations should use
    29  	// constant-time comparisons if possible.
    30  	VerifyState(r *http.Request, state string) (bool, error)
    31  }
    32  
    33  const (
    34  	insecureState = "insecure-for-testing-only"
    35  )
    36  
    37  type insecureStateStore struct{}
    38  
    39  func (ss insecureStateStore) GenerateState(w http.ResponseWriter, r *http.Request) (string, error) {
    40  	return insecureState, nil
    41  }
    42  
    43  func (ss insecureStateStore) VerifyState(r *http.Request, state string) (bool, error) {
    44  	return insecureState == state, nil
    45  }
    46  

View as plain text