Skip to content

Commit

Permalink
* Allows reuse of access token, for example the same user / client
Browse files Browse the repository at this point in the history
  • Loading branch information
RangelReale committed Sep 10, 2014
1 parent 1bb768e commit 1f4e975
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions access.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ type AccessRequest struct {
Client Client
AuthorizeData *AuthorizeData
AccessData *AccessData
RedirectUri string
Scope string
Username string
Password string
AssertionType string
Assertion string

// Force finish to use this access data, to allow access data reuse
ForceAccessData *AccessData
RedirectUri string
Scope string
Username string
Password string
AssertionType string
Assertion string

// Set if request is authorized
Authorized bool
Expand Down Expand Up @@ -394,26 +397,31 @@ func (s *Server) FinishAccessRequest(w *Response, r *http.Request, ar *AccessReq
redirectUri = ar.RedirectUri
}
if ar.Authorized {
// generate access token
ret := &AccessData{
Client: ar.Client,
AuthorizeData: ar.AuthorizeData,
AccessData: ar.AccessData,
RedirectUri: redirectUri,
CreatedAt: time.Now(),
ExpiresIn: ar.Expiration,
UserData: ar.UserData,
Scope: ar.Scope,
}

var ret *AccessData
var err error

// generate access token
ret.AccessToken, ret.RefreshToken, err = s.AccessTokenGen.GenerateAccessToken(ret, ar.GenerateRefresh)
if err != nil {
w.SetError(E_SERVER_ERROR, "")
w.InternalError = err
return
if ar.ForceAccessData == nil {
// generate access token
ret = &AccessData{
Client: ar.Client,
AuthorizeData: ar.AuthorizeData,
AccessData: ar.AccessData,
RedirectUri: redirectUri,
CreatedAt: time.Now(),
ExpiresIn: ar.Expiration,
UserData: ar.UserData,
Scope: ar.Scope,
}

// generate access token
ret.AccessToken, ret.RefreshToken, err = s.AccessTokenGen.GenerateAccessToken(ret, ar.GenerateRefresh)
if err != nil {
w.SetError(E_SERVER_ERROR, "")
w.InternalError = err
return
}
} else {
ret = ar.ForceAccessData
}

// save access token
Expand Down

0 comments on commit 1f4e975

Please sign in to comment.