Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oauth2: Returns token type on introspection #832

Merged
merged 3 commits into from
Apr 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

[[constraint]]
name = "github.com/ory/fosite"
version = "0.17.0"
version = "0.18.0"

[[constraint]]
name = "github.com/ory/graceful"
Expand Down
10 changes: 8 additions & 2 deletions oauth2/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,17 @@ func (h *Handler) WellKnownHandler(w http.ResponseWriter, r *http.Request, _ htt
// 500: genericError
func (h *Handler) UserinfoHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
session := NewSession("")
ar, err := h.OAuth2.IntrospectToken(r.Context(), fosite.AccessTokenFromRequest(r), fosite.AccessToken, session)
tokenType, ar, err := h.OAuth2.IntrospectToken(r.Context(), fosite.AccessTokenFromRequest(r), fosite.AccessToken, session)
if err != nil {
h.H.WriteError(w, r, err)
return
}

if tokenType != fosite.AccessToken {
h.H.WriteErrorCode(w, r, http.StatusUnauthorized, errors.New("Only access tokens are allowed in the authorization header"))
return
}

interim := ar.GetSession().(*Session).IDTokenClaims().ToMap()
delete(interim, "aud")
delete(interim, "iss")
Expand Down Expand Up @@ -311,7 +316,7 @@ func (h *Handler) IntrospectHandler(w http.ResponseWriter, r *http.Request, _ ht

w.Header().Set("Content-Type", "application/json;charset=UTF-8")
if err = json.NewEncoder(w).Encode(&Introspection{
Active: true,
Active: resp.IsActive(),
ClientID: resp.GetAccessRequester().GetClient().GetID(),
Scope: strings.Join(resp.GetAccessRequester().GetGrantedScopes(), " "),
ExpiresAt: exp.Unix(),
Expand All @@ -321,6 +326,7 @@ func (h *Handler) IntrospectHandler(w http.ResponseWriter, r *http.Request, _ ht
Extra: resp.GetAccessRequester().GetSession().(*Session).Extra,
Audience: resp.GetAccessRequester().GetSession().(*Session).Audience,
Issuer: h.Issuer,
TokenType: string(resp.GetTokenType()),
}); err != nil {
pkg.LogError(errors.WithStack(err), h.L)
}
Expand Down
3 changes: 3 additions & 0 deletions oauth2/introspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ type Introspection struct {
// Issuer is a string representing the issuer of this token
Issuer string `json:"iss,omitempty"`

// TokenType is the introspected token's type, for example `access_token` or `refresh_token`.
TokenType string `json:"token_type,omitempty"`

// Extra is arbitrary data set by the session.
Extra map[string]interface{} `json:"ext,omitempty"`
}