github.com/cs3org/reva/v2@v2.27.7/pkg/auth/auth.go (about) 1 // Copyright 2018-2021 CERN 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 // In applying this license, CERN does not waive the privileges and immunities 16 // granted to it by virtue of its status as an Intergovernmental Organization 17 // or submit itself to any jurisdiction. 18 19 package auth 20 21 import ( 22 "context" 23 "net/http" 24 25 authpb "github.com/cs3org/go-cs3apis/cs3/auth/provider/v1beta1" 26 registry "github.com/cs3org/go-cs3apis/cs3/auth/registry/v1beta1" 27 user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" 28 "github.com/cs3org/reva/v2/pkg/plugin" 29 ) 30 31 // Manager is the interface to implement to authenticate users 32 type Manager interface { 33 plugin.Plugin 34 Authenticate(ctx context.Context, clientID, clientSecret string) (*user.User, map[string]*authpb.Scope, error) 35 } 36 37 // Credentials contains the auth type, client id and secret. 38 type Credentials struct { 39 Type string 40 ClientID string 41 ClientSecret string 42 } 43 44 // CredentialStrategy obtains Credentials from the request. 45 type CredentialStrategy interface { 46 GetCredentials(w http.ResponseWriter, r *http.Request) (*Credentials, error) 47 AddWWWAuthenticate(w http.ResponseWriter, r *http.Request, realm string) 48 } 49 50 // TokenStrategy obtains a token from the request. 51 // If token does not exist returns an empty string. 52 type TokenStrategy interface { 53 GetToken(r *http.Request) string 54 } 55 56 // TokenWriter stores the token in a http response. 57 type TokenWriter interface { 58 WriteToken(token string, w http.ResponseWriter) 59 } 60 61 // Registry is the interface that auth registries implement 62 // for discovering auth providers 63 type Registry interface { 64 ListProviders(ctx context.Context) ([]*registry.ProviderInfo, error) 65 GetProvider(ctx context.Context, authType string) (*registry.ProviderInfo, error) 66 }