...

Source file src/github.com/ory/fosite/handler/openid/flow_explicit_auth.go

Documentation: github.com/ory/fosite/handler/openid

     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 openid
    23  
    24  import (
    25  	"context"
    26  
    27  	"github.com/ory/x/errorsx"
    28  
    29  	"github.com/ory/fosite"
    30  )
    31  
    32  type OpenIDConnectExplicitHandler struct {
    33  	// OpenIDConnectRequestStorage is the storage for open id connect sessions.
    34  	OpenIDConnectRequestStorage   OpenIDConnectRequestStorage
    35  	OpenIDConnectRequestValidator *OpenIDConnectRequestValidator
    36  
    37  	*IDTokenHandleHelper
    38  }
    39  
    40  var oidcParameters = []string{"grant_type",
    41  	"max_age",
    42  	"prompt",
    43  	"acr_values",
    44  	"id_token_hint",
    45  	"nonce",
    46  }
    47  
    48  func (c *OpenIDConnectExplicitHandler) HandleAuthorizeEndpointRequest(ctx context.Context, ar fosite.AuthorizeRequester, resp fosite.AuthorizeResponder) error {
    49  	if !(ar.GetGrantedScopes().Has("openid") && ar.GetResponseTypes().ExactOne("code")) {
    50  		return nil
    51  	}
    52  
    53  	//if !ar.GetClient().GetResponseTypes().Has("id_token", "code") {
    54  	//	return errorsx.WithStack(fosite.ErrInvalidRequest.WithDebug("The client is not allowed to use response type id_token and code"))
    55  	//}
    56  
    57  	if len(resp.GetCode()) == 0 {
    58  		return errorsx.WithStack(fosite.ErrMisconfiguration.WithDebug("The authorization code has not been issued yet, indicating a broken code configuration."))
    59  	}
    60  
    61  	if err := c.OpenIDConnectRequestValidator.ValidatePrompt(ctx, ar); err != nil {
    62  		return err
    63  	}
    64  
    65  	if err := c.OpenIDConnectRequestStorage.CreateOpenIDConnectSession(ctx, resp.GetCode(), ar.Sanitize(oidcParameters)); err != nil {
    66  		return errorsx.WithStack(fosite.ErrServerError.WithWrap(err).WithDebug(err.Error()))
    67  	}
    68  
    69  	// there is no need to check for https, because it has already been checked by core.explicit
    70  
    71  	return nil
    72  }
    73  

View as plain text