...

Source file src/github.com/ory/fosite/access_response_writer.go

Documentation: github.com/ory/fosite

     1  /*
     2   * Copyright © 2015-2018 Aeneas Rekkas <aeneas+oss@aeneas.io>
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   *
    16   * @author		Aeneas Rekkas <aeneas+oss@aeneas.io>
    17   * @copyright 	2015-2018 Aeneas Rekkas <aeneas+oss@aeneas.io>
    18   * @license 	Apache-2.0
    19   *
    20   */
    21  
    22  package fosite
    23  
    24  import (
    25  	"context"
    26  
    27  	"github.com/ory/x/errorsx"
    28  
    29  	"github.com/pkg/errors"
    30  )
    31  
    32  func (f *Fosite) NewAccessResponse(ctx context.Context, requester AccessRequester) (AccessResponder, error) {
    33  	var err error
    34  	var tk TokenEndpointHandler
    35  
    36  	response := NewAccessResponse()
    37  
    38  	ctx = context.WithValue(ctx, AccessRequestContextKey, requester)
    39  	ctx = context.WithValue(ctx, AccessResponseContextKey, response)
    40  
    41  	for _, tk = range f.TokenEndpointHandlers {
    42  		if err = tk.PopulateTokenEndpointResponse(ctx, requester, response); err == nil {
    43  			// do nothing
    44  		} else if errors.Is(err, ErrUnknownRequest) {
    45  			// do nothing
    46  		} else if err != nil {
    47  			return nil, err
    48  		}
    49  	}
    50  
    51  	if response.GetAccessToken() == "" || response.GetTokenType() == "" {
    52  		return nil, errorsx.WithStack(ErrServerError.WithHint("An internal server occurred while trying to complete the request.").WithDebug("Access token or token type not set by TokenEndpointHandlers.").WithLocalizer(f.MessageCatalog, getLangFromRequester(requester)))
    53  	}
    54  
    55  	return response, nil
    56  }
    57  

View as plain text