improve: OAuth2 UI and test suite (via #5066)

* create `features` folder

* add base oauth2 server

* continue implementing OAuth tests

* WIP

* add password flow tests

* modify Password flow credential types

* remove query string credential type

* add test case for Authorization flow

* add specific Authorization value for Password flow test

* WIP

* fix linter issues
This commit is contained in:
kyle
2018-12-07 20:54:29 +01:00
committed by GitHub
parent 91b1becc65
commit a5568f9e16
14 changed files with 504 additions and 55 deletions

View File

@@ -74,28 +74,23 @@ export const authorizePassword = ( auth ) => ( { authActions } ) => {
let { schema, name, username, password, passwordType, clientId, clientSecret } = auth
let form = {
grant_type: "password",
scope: auth.scopes.join(scopeSeparator)
scope: auth.scopes.join(scopeSeparator),
username,
password
}
let query = {}
let headers = {}
if ( passwordType === "basic") {
headers.Authorization = "Basic " + btoa(username + ":" + password)
} else {
Object.assign(form, {username}, {password})
switch (passwordType) {
case "request-body":
setClientIdAndSecret(form, clientId, clientSecret)
break
switch ( passwordType ) {
case "query":
setClientIdAndSecret(query, clientId, clientSecret)
break
case "request-body":
setClientIdAndSecret(form, clientId, clientSecret)
break
default:
headers.Authorization = "Basic " + btoa(clientId + ":" + clientSecret)
}
case "basic":
headers.Authorization = "Basic " + btoa(clientId + ":" + clientSecret)
break
default:
console.warn(`Warning: invalid passwordType ${passwordType} was passed, not including client id and secret`)
}
return authActions.authorizeRequest({ body: buildFormData(form), url: schema.get("tokenUrl"), name, headers, query, auth})