-
-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Device grant flow (migrate to master)
- Loading branch information
1 parent
575ae6d
commit ce02ff3
Showing
58 changed files
with
2,002 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package fosite | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/ory/fosite/i18n" | ||
"github.com/ory/x/errorsx" | ||
) | ||
|
||
func (f *Fosite) NewDeviceAuthorizeRequest(ctx context.Context, req *http.Request) (Requester, error) { | ||
|
||
request := NewRequest() | ||
request.Lang = i18n.GetLangFromRequest(f.Config.GetMessageCatalog(ctx), req) | ||
|
||
if err := req.ParseMultipartForm(1 << 20); err != nil && err != http.ErrNotMultipart { | ||
return request, errorsx.WithStack(ErrInvalidRequest.WithHint("Unable to parse HTTP body, make sure to send a properly formatted form request body.").WithWrap(err).WithDebug(err.Error())) | ||
} | ||
request.Form = req.PostForm | ||
|
||
client, err := f.Store.GetClient(ctx, request.GetRequestForm().Get("client_id")) | ||
if err != nil { | ||
return request, errorsx.WithStack(ErrInvalidClient.WithHint("The requested OAuth 2.0 Client does not exist.").WithWrap(err).WithDebug(err.Error())) | ||
} | ||
request.Client = client | ||
|
||
if err := f.validateDeviceAuthorizeScope(ctx, request); err != nil { | ||
return request, err | ||
} | ||
|
||
return request, nil | ||
} | ||
|
||
func (f *Fosite) validateDeviceAuthorizeScope(ctx context.Context, request *Request) error { | ||
scope := RemoveEmpty(strings.Split(request.Form.Get("scope"), " ")) | ||
for _, permission := range scope { | ||
if !f.Config.GetScopeStrategy(ctx)(request.Client.GetScopes(), permission) { | ||
return errorsx.WithStack(ErrInvalidScope.WithHintf("The OAuth 2.0 Client is not allowed to request scope '%s'.", permission)) | ||
} | ||
} | ||
request.SetRequestedScopes(scope) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package fosite | ||
|
||
import "context" | ||
|
||
type DeviceAuthorizeResponse struct { | ||
context context.Context | ||
deviceCode string | ||
userCode string | ||
verificationURI string | ||
verificationURIComplete string | ||
interval int | ||
expiresIn int64 | ||
} | ||
|
||
// GetDeviceCode returns the response's device code | ||
func NewDeviceAuthorizeResponse() *DeviceAuthorizeResponse { | ||
return &DeviceAuthorizeResponse{} | ||
} | ||
|
||
func (d *DeviceAuthorizeResponse) GetDeviceCode() string { | ||
return d.deviceCode | ||
} | ||
|
||
// GetUserCode returns the response's user code | ||
func (d *DeviceAuthorizeResponse) SetDeviceCode(code string) { | ||
d.deviceCode = code | ||
} | ||
|
||
func (d *DeviceAuthorizeResponse) GetUserCode() string { | ||
return d.userCode | ||
} | ||
|
||
func (d *DeviceAuthorizeResponse) SetUserCode(code string) { | ||
d.userCode = code | ||
} | ||
|
||
// GetVerificationURI returns the response's verification uri | ||
func (d *DeviceAuthorizeResponse) GetVerificationURI() string { | ||
return d.verificationURI | ||
} | ||
|
||
func (d *DeviceAuthorizeResponse) SetVerificationURI(uri string) { | ||
d.verificationURI = uri | ||
} | ||
|
||
// GetVerificationURIComplete returns the response's complete verification uri if set | ||
func (d *DeviceAuthorizeResponse) GetVerificationURIComplete() string { | ||
return d.verificationURIComplete | ||
} | ||
|
||
func (d *DeviceAuthorizeResponse) SetVerificationURIComplete(uri string) { | ||
d.verificationURIComplete = uri | ||
} | ||
|
||
// GetExpiresIn returns the response's device code and user code lifetime in seconds if set | ||
func (d *DeviceAuthorizeResponse) GetExpiresIn() int64 { | ||
return d.expiresIn | ||
} | ||
|
||
func (d *DeviceAuthorizeResponse) SetExpiresIn(seconds int64) { | ||
d.expiresIn = seconds | ||
} | ||
|
||
// GetInterval returns the response's polling interval if set | ||
func (d *DeviceAuthorizeResponse) GetInterval() int { | ||
return d.interval | ||
} | ||
|
||
func (d *DeviceAuthorizeResponse) SetInterval(seconds int) { | ||
d.interval = seconds | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package fosite | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
) | ||
|
||
func (f *Fosite) NewDeviceAuthorizeResponse(ctx context.Context, r Requester) (DeviceAuthorizeResponder, error) { | ||
var resp = NewDeviceAuthorizeResponse() | ||
|
||
for _, h := range f.Config.GetDeviceAuthorizeEndpointHandlers(ctx) { | ||
fmt.Println("NewDeviceAuthorizeResponse +++") | ||
if err := h.HandleDeviceAuthorizeEndpointRequest(ctx, r, resp); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return resp, nil | ||
} |
Oops, something went wrong.