PKG OAuth : add package to simplify oauth2 uses

This commit is contained in:
Nicolas JUHEL
2020-09-11 13:54:54 +02:00
parent 91aaaaf614
commit 069eacbe03
2 changed files with 156 additions and 0 deletions

60
oauth/error.go Normal file
View File

@@ -0,0 +1,60 @@
/*
* MIT License
*
* Copyright (c) 2020 Nicolas JUHEL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*
*/
package oauth
import (
"github.com/nabbar/golib/errors"
)
const (
ErrorEmptyParams errors.CodeError = iota + errors.MIN_PKG_OAuth
ErrorOAuthExchange
)
var isCodeError = false
func IsCodeError() bool {
return isCodeError
}
func init() {
isCodeError = errors.ExistInMapMessage(ErrorEmptyParams)
errors.RegisterIdFctMessage(ErrorEmptyParams, getMessage)
}
func getMessage(code errors.CodeError) (message string) {
switch code {
case errors.UNK_ERROR:
return ""
case ErrorEmptyParams:
return "given parameters is empty"
case ErrorOAuthExchange:
return "code seems to be invalid when trying to get token from it"
}
return ""
}