本文整理匯總了Golang中github.com/RangelReale/osin.Client.Id方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Id方法的具體用法?Golang Client.Id怎麽用?Golang Client.Id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/RangelReale/osin.Client
的用法示例。
在下文中一共展示了Client.Id方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: createOauthClient
func createOauthClient(w http.ResponseWriter, r *http.Request) {
var responseMessage []byte
code := 200
if r.Method == "POST" {
decoder := json.NewDecoder(r.Body)
var newOauthClient NewClientRequest
err := decoder.Decode(&newOauthClient)
if err != nil {
responseMessage = []byte(E_SYSTEM_ERROR)
code = 500
log.Error("Couldn't decode body")
log.Error(err)
}
u5, err := uuid.NewV4()
cleanSting := strings.Replace(u5.String(), "-", "", -1)
u5Secret, err := uuid.NewV4()
secret := base64.StdEncoding.EncodeToString([]byte(u5Secret.String()))
newClient := osin.Client{}
newClient.Id = cleanSting
newClient.RedirectUri = newOauthClient.ClientRedirectURI
newClient.Secret = secret
storageID := createOauthClientStorageID(newOauthClient.APIID, newClient.Id)
storeErr := genericOsinStorage.SetClient(storageID, &newClient, true)
if storeErr != nil {
log.Error("Failed to save new client data: ", storeErr)
responseMessage = createError("Failure in storing client data.")
}
reportableClientData := OAuthClient{
ClientID: newClient.Id,
ClientSecret: newClient.Secret,
ClientRedirectURI: newClient.RedirectUri,
}
responseMessage, err = json.Marshal(&reportableClientData)
if err != nil {
log.Error("Marshalling failed")
log.Error(err)
responseMessage = []byte(E_SYSTEM_ERROR)
code = 500
} else {
log.WithFields(logrus.Fields{
"key": newClient.Id,
}).Info("New OAuth Client registered successfully.")
}
} else {
code = 405
responseMessage = createError("Method not supported")
}
w.WriteHeader(code)
fmt.Fprintf(w, string(responseMessage))
}