github.com/jenkins-x/test-infra@v0.0.7/prow/config/githuboauth.go (about)

     1  /*
     2  Copyright 2018 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package config
    18  
    19  import (
    20  	"encoding/gob"
    21  
    22  	"github.com/gorilla/sessions"
    23  	"golang.org/x/oauth2"
    24  )
    25  
    26  // Cookie holds the secret returned from github that authenticates the user who authorized this app.
    27  type Cookie struct {
    28  	Secret string `json:"secret,omitempty"`
    29  }
    30  
    31  // GithubOAuthConfig is a config for requesting users access tokens from Github API. It also has
    32  // a Cookie Store that retains user credentials deriving from Github API.
    33  type GithubOAuthConfig struct {
    34  	ClientID         string   `json:"client_id"`
    35  	ClientSecret     string   `json:"client_secret"`
    36  	RedirectURL      string   `json:"redirect_url"`
    37  	Scopes           []string `json:"scopes,omitempty"`
    38  	FinalRedirectURL string   `json:"final_redirect_url"`
    39  
    40  	CookieStore *sessions.CookieStore `json:"-"`
    41  }
    42  
    43  // InitGithubOAuthConfig creates an OAuthClient using GithubOAuth config and a Cookie Store
    44  // to retain user credentials.
    45  func (gac *GithubOAuthConfig) InitGithubOAuthConfig(cookie *sessions.CookieStore) {
    46  	gob.Register(&oauth2.Token{})
    47  	gac.CookieStore = cookie
    48  }