// AuthorizeToken authorizes a given token to access a given URL.
8502
func (s *service) AuthorizeToken(ctx context.Context, hostname, path, token string) (*sessions.Session, error) {
	resourceCh, resourceErrCh := make(chan *resources.Resource, 1), make(chan error, 1)
	sessionCh, sessionErrCh := make(chan *sessions.Session, 1), make(chan error, 1)
	go func() {
		session, err := s.sessionRepo.FindByToken(ctx, token)
		if err != nil {
			sessionErrCh <- err
			close(sessionCh)
			return
		}
		sessionCh <- session
		close(sessionErrCh)
	}()
	go func() {
		resource, err := s.resourceRepo.FindByHostname(ctx, hostname)
		if err != nil {
			resourceErrCh <- err
			close(resourceCh)
			return
		}
		resourceCh <- resource
		close(resourceErrCh)
	}()
	// If we can't find a resource, we deny the access
	// Otherwise, the access is denied with an error
	if err := <-resourceErrCh; err != nil {
		if isErrNotFound(err) {
			return nil, withErrDeniedAccess(err)
		}
		return nil, err

	}
	resource := <-resourceCh
	// If the found resource is marked as public, we allow the access without condition
	if resource.Public != nil && *resource.Public {
		return nil, nil
	}
	// If no session is found for the token, we initiate a guest session
	// Otherwise, the access is denied with an error
	if err := <-sessionErrCh; err != nil {
		if isErrNotFound(err) {
			return s.authorizeGuestSession(ctx, path, resource.Name)
		}
		return nil, err
	}
	foundSession := <-sessionCh
	// If a session is found, we try to authorize it
	session, err := s.authorizeSession(ctx, path, resource.Name, foundSession)
	if err != nil {
		// If denied, we at least try to authorize as guest
		if isErrDeniedAccess(err) {
			if _, err := s.authorizeGuestSession(ctx, path, resource.Name); err != nil {
				return nil, err
			}
			return foundSession, nil
		}
		return nil, err
	}
	// If found, we return it
	return session, nil
}
1346800
func (s *DescribeCommentsInput) SetAuthenticationToken(v string) *DescribeCommentsInput {
	s.AuthenticationToken = &v
	return s
}
1060527
func GetToken(ctx context.Context) (string, error) {
	a, ok := ctx.Value(authorizerCtxKey).(platform.Authorizer)
	if !ok {
		return "", &platform.Error{
			Msg:  "authorizer not found on context",
			Code: platform.EInternal,
		}
	}

	auth, ok := a.(*platform.Authorization)
	if !ok {
		return "", &platform.Error{
			Msg:  fmt.Sprintf("authorizer not an authorization but a %T", a),
			Code: platform.EInternal,
		}
	}

	return auth.Token, nil
}
867784
func (s *UpdateDocumentInput) SetAuthenticationToken(v string) *UpdateDocumentInput {
	s.AuthenticationToken = &v
	return s
}
191420
func GetAuthorizeUrl(client *FlickrClient, reqToken *RequestToken) (string, error) {
	client.EndpointUrl = AUTHORIZE_URL
	client.Args = url.Values{}
	client.Args.Set("oauth_token", reqToken.OauthToken)
	// TODO make permission value parametric
	client.Args.Set("perms", "delete")

	return client.GetUrl(), nil
}
1373674
func (s *CreateFolderInput) SetAuthenticationToken(v string) *CreateFolderInput {
	s.AuthenticationToken = &v
	return s
}
1219938
func signToken(secret []byte, token *AccessToken) (string, error) {
	t := accessTokenToJwt(token)
	return t.SignedString(secret)
}
1304512
func (a tagKindAuthorizer) Authorize(authInfo httpcontext.AuthInfo) error {
	tagKind := authInfo.Entity.Tag().Kind()
	for _, kind := range a {
		if tagKind == kind {
			return nil
		}
	}
	return errors.NotValidf("tag kind %v", tagKind)
}
1100935
func (c *UserConfig) GetAuthorizeURL(service *Service) (string, error) {
	if c.RequestTokenKey == "" || c.RequestTokenSecret == "" {
		return "", fmt.Errorf("No configured request token")
	}
	token := url.QueryEscape(c.RequestTokenKey)
	return service.AuthorizeURL + "?oauth_token=" + token, nil
}
1086753
func (c *ContivClient) SetAuthToken(token string) error {

	// setting an auth token is only allowed on secure requests.
	// if we didn't enforce this, the client could potentially send auth
	// tokens in plain text across the network.
	if !c.isHTTPS() {
		return errors.New("setting auth token requires a https auth_proxy URL")
	}

	// having multiple auth token headers is confusing and makes no sense and
	// which one is actually used depends on the implementation of the server.
	// therefore, we will raise an error if there's already an auth token set.
	for _, pair := range c.customRequestHeaders {
		if pair[0] == authTokenHeader {
			return errors.New("an auth token has already been set")
		}
	}

	c.addCustomRequestHeader(authTokenHeader, token)

	return nil
}
881741
func (a *Authenticator) Authorize(ctx context.Context, w http.ResponseWriter, p oauth2.Principal) error {
	cookie := http.Cookie{}

	http.SetCookie(w, &cookie)
	return nil
}
1339699
func (s *AbortDocumentVersionUploadInput) SetAuthenticationToken(v string) *AbortDocumentVersionUploadInput {
	s.AuthenticationToken = &v
	return s
}
1276070
func (s *CreateReplicationGroupInput) SetAuthToken(v string) *CreateReplicationGroupInput {
	s.AuthToken = &v
	return s
}
154836
func (s *Session) Authorize(provider goth.Provider, params goth.Params) (string, error) {
	p := provider.(*Provider)
	token, err := p.config.Exchange(goth.ContextForClient(p.Client()), params.Get("code"))
	if err != nil {
		return "", err
	}

	if !token.Valid() {
		return "", errors.New("Invalid token received from provider")
	}

	email, ok := token.Extra("email").(string)
	if !ok {
		return "", errors.New("Cannot fetch user email")
	}

	s.AccessToken = token.AccessToken
	s.ExpiresAt = token.Expiry
	s.email = email
	return s.AccessToken, err
}
960887
func HasAuthorizedToken(auth oauth2.Authenticator, r *http.Request) (oauth2.Principal, error) {
	ctx := r.Context()
	return auth.Validate(ctx, r)
}
807360
func (s *GetFolderInput) SetAuthenticationToken(v string) *GetFolderInput {
	s.AuthenticationToken = &v
	return s
}
14603
func (s *AddResourcePermissionsInput) SetAuthenticationToken(v string) *AddResourcePermissionsInput {
	s.AuthenticationToken = &v
	return s
}