2021-02-21 22:33:53 +08:00
|
|
|
// Copyright 2021 The casbin Authors. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package idp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"golang.org/x/oauth2"
|
|
|
|
)
|
|
|
|
|
|
|
|
type IdProvider interface {
|
|
|
|
GetConfig() *oauth2.Config
|
2021-02-21 23:51:40 +08:00
|
|
|
GetUserInfo(httpClient *http.Client, token *oauth2.Token) (string, string, string, error)
|
2021-02-21 22:33:53 +08:00
|
|
|
}
|
|
|
|
|
2021-03-22 20:00:35 +08:00
|
|
|
func GetIdProvider(providerType string, clientId string) IdProvider {
|
2021-02-21 22:33:53 +08:00
|
|
|
if providerType == "github" {
|
|
|
|
return &GithubIdProvider{}
|
2021-02-21 23:51:40 +08:00
|
|
|
} else if providerType == "google" {
|
|
|
|
return &GoogleIdProvider{}
|
2021-03-22 20:00:35 +08:00
|
|
|
} else if providerType == "qq" {
|
|
|
|
return &QqIdProvider{ClientId: clientId}
|
2021-02-21 22:33:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|