• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang network.NewTokenAuthorization函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/pivotal-cf-experimental/warrant/internal/network.NewTokenAuthorization函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTokenAuthorization函数的具体用法?Golang NewTokenAuthorization怎么用?Golang NewTokenAuthorization使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewTokenAuthorization函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Create

func (us UsersService) Create(username, email, token string) (User, error) {
	resp, err := newNetworkClient(us.config).MakeRequest(network.Request{
		Method:        "POST",
		Path:          "/Users",
		Authorization: network.NewTokenAuthorization(token),
		Body: network.NewJSONRequestBody(documents.CreateUserRequest{
			UserName: username,
			Emails: []documents.Email{
				{Value: email},
			},
		}),
		AcceptableStatusCodes: []int{http.StatusCreated},
	})
	if err != nil {
		return User{}, translateError(err)
	}

	var response documents.UserResponse
	err = json.Unmarshal(resp.Body, &response)
	if err != nil {
		return User{}, MalformedResponseError{err}
	}

	return newUserFromResponse(us.config, response), nil
}
开发者ID:jrbudnack,项目名称:notifications-release,代码行数:25,代码来源:users_service.go


示例2: Find

func (us UsersService) Find(query UsersQuery, token string) ([]User, error) {
	requestPath := url.URL{
		Path: "/Users",
		RawQuery: url.Values{
			"filter": []string{query.Filter},
		}.Encode(),
	}

	resp, err := newNetworkClient(us.config).MakeRequest(network.Request{
		Method:                "GET",
		Path:                  requestPath.String(),
		Authorization:         network.NewTokenAuthorization(token),
		AcceptableStatusCodes: []int{http.StatusOK},
	})
	if err != nil {
		return []User{}, translateError(err)
	}

	var response documents.UserListResponse
	err = json.Unmarshal(resp.Body, &response)
	if err != nil {
		return []User{}, MalformedResponseError{err}
	}

	var userList []User
	for _, userResponse := range response.Resources {
		userList = append(userList, newUserFromResponse(us.config, userResponse))
	}

	return userList, err
}
开发者ID:jrbudnack,项目名称:notifications-release,代码行数:31,代码来源:users_service.go


示例3: Delete

// Delete will make a request to UAA to delete the group resource with the matching id.
// A token with the "scim.write" scope is required.
func (gs GroupsService) Delete(id, token string) error {
	_, err := newNetworkClient(gs.config).MakeRequest(network.Request{
		Method:                "DELETE",
		Path:                  fmt.Sprintf("/Groups/%s", id),
		Authorization:         network.NewTokenAuthorization(token),
		AcceptableStatusCodes: []int{http.StatusOK},
	})
	if err != nil {
		return translateError(err)
	}

	return nil
}
开发者ID:dieucao,项目名称:notifications,代码行数:15,代码来源:groups_service.go


示例4: Create

// Create will make a request to UAA to register a client with the given client resource and
// secret. A token with the "clients.write" scope is required.
func (cs ClientsService) Create(client Client, secret, token string) error {
	_, err := newNetworkClient(cs.config).MakeRequest(network.Request{
		Method:        "POST",
		Path:          "/oauth/clients",
		Authorization: network.NewTokenAuthorization(token),
		Body:          network.NewJSONRequestBody(client.toDocument(secret)),
		AcceptableStatusCodes: []int{http.StatusCreated},
	})
	if err != nil {
		return translateError(err)
	}

	return nil
}
开发者ID:dieucao,项目名称:notifications,代码行数:16,代码来源:clients_service.go


示例5: SetPassword

func (us UsersService) SetPassword(id, password, token string) error {
	_, err := newNetworkClient(us.config).MakeRequest(network.Request{
		Method:        "PUT",
		Path:          fmt.Sprintf("/Users/%s/password", id),
		Authorization: network.NewTokenAuthorization(token),
		Body: network.NewJSONRequestBody(documents.SetPasswordRequest{
			Password: password,
		}),
		AcceptableStatusCodes: []int{http.StatusOK},
	})
	if err != nil {
		return translateError(err)
	}

	return nil
}
开发者ID:jrbudnack,项目名称:notifications-release,代码行数:16,代码来源:users_service.go


示例6: Get

// Get will make a request to UAA to fetch the group resource with the matching id.
// A token with the "scim.read" scope is required.
func (gs GroupsService) Get(id, token string) (Group, error) {
	resp, err := newNetworkClient(gs.config).MakeRequest(network.Request{
		Method:                "GET",
		Path:                  fmt.Sprintf("/Groups/%s", id),
		Authorization:         network.NewTokenAuthorization(token),
		AcceptableStatusCodes: []int{http.StatusOK},
	})
	if err != nil {
		return Group{}, translateError(err)
	}

	var response documents.GroupResponse
	err = json.Unmarshal(resp.Body, &response)
	if err != nil {
		return Group{}, MalformedResponseError{err}
	}

	return newGroupFromResponse(gs.config, response), nil
}
开发者ID:dieucao,项目名称:notifications,代码行数:21,代码来源:groups_service.go


示例7: Get

// Get will make a request to UAA to fetch the client matching the given id.
// A token with the "clients.read" scope is required.
func (cs ClientsService) Get(id, token string) (Client, error) {
	resp, err := newNetworkClient(cs.config).MakeRequest(network.Request{
		Method:                "GET",
		Path:                  fmt.Sprintf("/oauth/clients/%s", id),
		Authorization:         network.NewTokenAuthorization(token),
		AcceptableStatusCodes: []int{http.StatusOK},
	})
	if err != nil {
		return Client{}, translateError(err)
	}

	var document documents.ClientResponse
	err = json.Unmarshal(resp.Body, &document)
	if err != nil {
		return Client{}, MalformedResponseError{err}
	}

	return newClientFromDocument(document), nil
}
开发者ID:dieucao,项目名称:notifications,代码行数:21,代码来源:clients_service.go


示例8: Update

func (us UsersService) Update(user User, token string) (User, error) {
	resp, err := newNetworkClient(us.config).MakeRequest(network.Request{
		Method:        "PUT",
		Path:          fmt.Sprintf("/Users/%s", user.ID),
		Authorization: network.NewTokenAuthorization(token),
		IfMatch:       strconv.Itoa(user.Version),
		Body:          network.NewJSONRequestBody(newUpdateUserDocumentFromUser(user)),
		AcceptableStatusCodes: []int{http.StatusOK},
	})
	if err != nil {
		return User{}, translateError(err)
	}

	var response documents.UserResponse
	err = json.Unmarshal(resp.Body, &response)
	if err != nil {
		return User{}, MalformedResponseError{err}
	}

	return newUserFromResponse(us.config, response), nil
}
开发者ID:jrbudnack,项目名称:notifications-release,代码行数:21,代码来源:users_service.go


示例9: Create

// Create will make a request to UAA to create a new group resource with the given
// DisplayName. A token with the "scim.write" scope is required.
func (gs GroupsService) Create(displayName, token string) (Group, error) {
	resp, err := newNetworkClient(gs.config).MakeRequest(network.Request{
		Method:        "POST",
		Path:          "/Groups",
		Authorization: network.NewTokenAuthorization(token),
		Body: network.NewJSONRequestBody(documents.CreateGroupRequest{
			DisplayName: displayName,
			Schemas:     schemas,
		}),
		AcceptableStatusCodes: []int{http.StatusCreated},
	})
	if err != nil {
		return Group{}, translateError(err)
	}

	var response documents.GroupResponse
	err = json.Unmarshal(resp.Body, &response)
	if err != nil {
		return Group{}, MalformedResponseError{err}
	}

	return newGroupFromResponse(gs.config, response), nil
}
开发者ID:dieucao,项目名称:notifications,代码行数:25,代码来源:groups_service.go


示例10: List

// List wil make a request to UAA to list the groups that match the given Query.
// A token with the "scim.read" scope is required.
func (gs GroupsService) List(query Query, token string) ([]Group, error) {
	resp, err := newNetworkClient(gs.config).MakeRequest(network.Request{
		Method:                "GET",
		Path:                  "/Groups",
		Authorization:         network.NewTokenAuthorization(token),
		AcceptableStatusCodes: []int{http.StatusOK},
	})
	if err != nil {
		return []Group{}, translateError(err)
	}

	var response documents.GroupListResponse
	err = json.Unmarshal(resp.Body, &response)
	if err != nil {
		return []Group{}, MalformedResponseError{err}
	}

	var groupList []Group
	for _, groupResponse := range response.Resources {
		groupList = append(groupList, newGroupFromResponse(gs.config, groupResponse))
	}

	return groupList, err
}
开发者ID:dieucao,项目名称:notifications,代码行数:26,代码来源:groups_service.go


示例11:

	})

	AfterEach(func() {
		fakeServer.Close()
	})

	Describe("makeRequest", func() {
		It("can make requests", func() {
			jsonBody := map[string]interface{}{
				"hello": "goodbye",
			}

			resp, err := client.MakeRequest(network.Request{
				Method:        "GET",
				Path:          "/path",
				Authorization: network.NewTokenAuthorization(token),
				Body:          network.NewJSONRequestBody(jsonBody),
				AcceptableStatusCodes: []int{http.StatusOK},
			})
			Expect(err).NotTo(HaveOccurred())
			Expect(resp.Code).To(Equal(http.StatusOK))
			Expect(resp.Body).To(MatchJSON(`{
				"body": "{\"hello\":\"goodbye\"}",
				"headers": {
					"Accept":          ["application/json"],
					"Accept-Encoding": ["gzip"],
					"Authorization":   ["Bearer TOKEN"],
					"Content-Length":  ["19"],
					"Content-Type":    ["application/json"],
					"User-Agent":      ["Go 1.1 package http"]
				}
开发者ID:dieucao,项目名称:notifications,代码行数:31,代码来源:client_test.go


示例12:

package network_test

import (
	"github.com/pivotal-cf-experimental/warrant/internal/network"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("RequestAuthorization", func() {
	Describe("TokenAuthorization", func() {
		It("returns a bearer token given a token value", func() {
			auth := network.NewTokenAuthorization("TOKEN")

			Expect(auth.Authorization()).To(Equal("Bearer TOKEN"))
		})
	})

	Describe("BasicAuthorization", func() {
		It("returns a basic auth header given a username and password", func() {
			auth := network.NewBasicAuthorization("username", "password")

			Expect(auth.Authorization()).To(Equal("Basic dXNlcm5hbWU6cGFzc3dvcmQ="))
		})
	})
})
开发者ID:jrbudnack,项目名称:notifications-release,代码行数:26,代码来源:authorization_test.go



注:本文中的github.com/pivotal-cf-experimental/warrant/internal/network.NewTokenAuthorization函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang redis.LocalRepository类代码示例发布时间:2022-05-28
下一篇:
Golang config_finder.BBSConfig类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap