Socket
Socket
Sign inDemoInstall

@advanced-rest-client/authorization-method

Package Overview
Dependencies
46
Maintainers
3
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.15 to 0.2.0

555

custom-elements.json
{
"version": 2,
"version": "experimental",
"tags": [
{
"name": "authorization-method",
"properties": "An element to render an UI for various authorization methods",
"path": "./authorization-method.js",
"description": "An element that renders various authorization methods.\n\n## Development\n\nThe element mixes in multiple mixins from `src/` directory.\nEach mixin support an authorization method. When selection change (the `type`\nproperty) a render function from corresponding mixin is called.",
"attributes": [
{
"name": "type",
"description": "Authorization method type.\n\nSupported types are (case insensitive, spaces sensitive):\n\n- Basic\n- Client certificate\n- Digest\n- NTLM\n- OAuth 1\n- OAuth 2\n\nDepending on selected type different properties are used.\nFor example Basic type only uses `username` and `password` properties,\nwhile NTLM also uses `domain` property.\n\nSee readme file for detailed list of properties depending on selected type.",
"type": "string"
},
{
"name": "readOnly",
"description": "When set the editor is in read only mode.",
"type": "boolean"
},
{
"name": "disabled",
"description": "When set the inputs are disabled",
"type": "boolean"
},
{
"name": "compatibility",
"description": "Enables compatibility with Anypoint components.",
"type": "boolean"
},
{
"name": "outlined",
"description": "Enables Material Design outlined style",
"type": "boolean"
},
{
"name": "narrow",
"description": "Renders mobile friendly view.",
"type": "boolean"
},
{
"name": "username",
"type": "string"
},
{
"name": "password",
"type": "string"
},
{
"name": "redirectUri",
"type": "string"
},
{
"name": "accessTokenUri",
"type": "string"
},
{
"name": "authorizationUri",
"type": "string"
},
{
"name": "domain",
"description": "Authorization domain\n\nUsed in the following types:\n- NTLM",
"type": "string | undefined"
},
{
"name": "algorithm",
"description": "The algorithm used to hash the response for Digest authorization.\n\nIt can be either `MD5` or `MD5-sess`.\n\nUsed in the following types:\n- Digest",
"type": "string"
},
{
"name": "qop",
"description": "The quality of protection value for the digest response.\nEither '', 'auth' or 'auth-int'\n\nUsed in the following types:\n- Digest",
"type": "string"
},
{
"name": "nc",
"description": "Nonce count - increments with each request used with the same nonce\n\nUsed in the following types:\n- Digest",
"type": "number"
},
{
"name": "cnonce",
"description": "Client nonce\n\nUsed in the following types:\n- Digest",
"type": "string"
},
{
"name": "opaque",
"description": "A string of data specified by the server\n\nUsed in the following types:\n- Digest",
"type": "string"
},
{
"name": "response",
"description": "Hashed response to server challenge\n\nUsed in the following types:\n- Digest",
"type": "string"
},
{
"name": "httpMethod",
"description": "Request HTTP method\n\nUsed in the following types:\n- Digest",
"type": "string"
},
{
"name": "requestUrl",
"description": "Current request URL.\n\nUsed in the following types:\n- Digest",
"type": "string"
},
{
"name": "requestBody",
"description": "Current request body.\n\nUsed in the following types:\n- Digest",
"type": "string"
},
{
"name": "consumerKey",
"description": "Used by OAuth 1",
"type": "string"
},
{
"name": "consumerSecret",
"description": "Used by OAuth 1",
"type": "string"
},
{
"name": "token",
"description": "Used by OAuth 1",
"type": "string"
},
{
"name": "tokenSecret",
"description": "Used by OAuth 1",
"type": "string"
},
{
"name": "timestamp",
"description": "Used by OAuth 1",
"type": "string"
},
{
"name": "nonce",
"description": "Server issued nonce for Digest authorization.\n\nUsed in the following types:\n- Digest\n- OAuth 1",
"type": "string"
},
{
"name": "realm",
"description": "Server issued realm for Digest authorization.\n\nUsed in the following types:\n- Digest",
"type": "string"
},
{
"name": "signatureMethod",
"description": "Used by OAuth 1",
"type": "string"
},
{
"name": "requestTokenUri",
"description": "Used by OAuth 1",
"type": "string"
},
{
"name": "authTokenMethod",
"description": "Used by OAuth 1",
"type": "string"
},
{
"name": "authParamsLocation",
"description": "Used by OAuth 1",
"type": "string"
},
{
"name": "responseType",
"description": "Selected authorization grand type.",
"type": "string"
},
{
"name": "clientId",
"description": "The client ID for the auth token.",
"type": "string"
},
{
"name": "clientSecret",
"description": "The client secret. It to be used when selected server flow.",
"type": "string"
},
{
"name": "preventCustomScopes",
"description": "If true then the `oauth2-scope-selector` will disallow to add a scope that is not\nin the `allowedScopes` list. Has no effect if the `allowedScopes` is not set.",
"type": "boolean"
},
{
"name": "accessToken",
"description": "When the user authorized the app it should be set to the token value.\nThis element do not perform authorization. Other elements must intercept\nthe token request event and perform the authorization.",
"type": "string"
},
{
"name": "tokenType",
"description": "By default it is \"bearer\" as the only one defined in OAuth 2.0 spec.\nIf the token response contains `tokenType` property then this value is updated.",
"type": "string | undefined"
},
{
"name": "advanced",
"description": "If set it renders authorization url, token url and scopes as advanced options\nwhich are then invisible by default. User can oen setting using the UI.",
"type": "boolean | undefined"
},
{
"name": "advancedOpened",
"description": "If true then the advanced options are opened.",
"type": "boolean | undefined"
},
{
"name": "noResponseType",
"description": "If set, the response type selector is hidden from the UI.",
"type": "boolean | undefined"
},
{
"name": "oauthDeliveryMethod",
"description": "Informs about what filed of the authenticated request the token property should be set.\nBy default the value is `header` which corresponds to the `authorization` by default,\nbut it is configured by the `deliveryName` property.\n\nThis can be used by the AMF model when the API spec defines where the access token should be\nput in the authenticated request.",
"type": "\"header\" | \"query\" | \"body\" | undefined",
"default": "\"header\""
},
{
"name": "oauthDeliveryName",
"description": "The name of the authenticated request property that carries the token.\nBy default it is `authorization` which corresponds to `header` value of the `deliveryMethod` property.\n\nBy setting both `deliveryMethod` and `deliveryName` you instruct the application (assuming it reads this values)\nwhere to put the authorization token.",
"type": "string | undefined",
"default": "\"authorization\""
},
{
"name": "baseUri",
"description": "The base URI to use to construct the correct URLs to the authorization endpoints.\n\nWhen the paths are relative then base URI is added to the path.\nRelative paths must start with '/'.\n\nNote, URL processing is happening internally in the component. The produced authorize event\nwill have base URI already applied.",
"type": "string | undefined"
}
],
"properties": [
{
"name": "styles",
"type": "CSSResult"
},
{
"name": "type",
"attribute": "type",
"type": "String",
"description": "Authorization method type.\n\nSupported types are (case insensitive, spaces sensitive):\n\n- Basic\n- Client certificate\n- Digest\n- NTLM\n- OAuth 1\n- OAuth 2\n\nDepending on selected type different properties are used.\nFor example Basic type only uses `username` and `password` properties,\nwhile NTLM also uses `domain` property."
"description": "Authorization method type.\n\nSupported types are (case insensitive, spaces sensitive):\n\n- Basic\n- Client certificate\n- Digest\n- NTLM\n- OAuth 1\n- OAuth 2\n\nDepending on selected type different properties are used.\nFor example Basic type only uses `username` and `password` properties,\nwhile NTLM also uses `domain` property.\n\nSee readme file for detailed list of properties depending on selected type.",
"type": "string"
},
{
"name": "readOnly",
"attribute": "readonly",
"type": "Boolean",
"description": "When set the editor is in read only mode."
"attribute": "readOnly",
"description": "When set the editor is in read only mode.",
"type": "boolean"
},

@@ -23,4 +247,4 @@ {

"attribute": "disabled",
"type": "Boolean",
"description": "When set the inputs are disabled."
"description": "When set the inputs are disabled",
"type": "boolean"
},

@@ -30,4 +254,4 @@ {

"attribute": "compatibility",
"type": "Boolean",
"description": "Enables compatibility with Anypoint components."
"description": "Enables compatibility with Anypoint components.",
"type": "boolean"
},

@@ -37,10 +261,20 @@ {

"attribute": "outlined",
"type": "Boolean",
"description": "Enables Material Design outlined style."
"description": "Enables Material Design outlined style",
"type": "boolean"
},
{
"name": "narrow",
"attribute": "narrow",
"description": "Renders mobile friendly view.",
"type": "boolean"
},
{
"name": "authorizing",
"description": "Used in the following types:\n- OAuth 1\n- OAuth 2",
"type": "boolean | null"
},
{
"name": "username",
"attribute": "username",
"type": "String",
"description": "Current username.\n\nUsed in the following types:\n- Basic\n- NTLM\n- Digest\n- OAuth 2"
"type": "string"
},

@@ -50,51 +284,39 @@ {

"attribute": "password",
"type": "String",
"description": "Current password.\n\nUsed in the following types:\n- Basic\n- NTLM\n- Digest\n- OAuth 2"
"type": "string"
},
{
"name": "redirectUri",
"attribute": "redirecturi",
"type": "String",
"description": "Authorization redirect URI.\n\nUsed in the following types:\n- OAuth 1\n- OAuth 2"
"attribute": "redirectUri",
"type": "string"
},
{
"name": "accessTokenUri",
"attribute": "accesstokenuri",
"type": "String",
"description": "An endpoint to authorize the token (OAuth 1) or exchange code for token (OAuth 2).\n\nUsed in the following types:\n- OAuth 1\n- OAuth 2"
"attribute": "accessTokenUri",
"type": "string"
},
{
"name": "authorizationUri",
"attribute": "authorizationuri",
"type": "String",
"description": "An URI of authentication endpoint where the user should be redirected to auththorize the app. This endpoint initialized OAuth flow.\n\nUsed in the following types:\n- OAuth 1\n- OAuth 2"
"attribute": "authorizationUri",
"type": "string"
},
{
"name": "authorizing",
"type": "Boolean",
"description": "True when currently authorizing the user. Note, this property is read only.\n\nUsed in the following types:\n- OAuth 1\n- OAuth 2"
"name": "onchange",
"type": "EventListener | null"
},
{
"name": "eventsTarget",
"description": "By default the element listens on the `window` object. If this value is set,\nthen all events listeners will be attached to this object instead of `window`.",
"type": "EventTarget"
},
{
"name": "domain",
"attribute": "domain",
"type": "String",
"description": "Authorization domain.\n\nUsed in the following types:\n- NTLM"
"description": "Authorization domain\n\nUsed in the following types:\n- NTLM",
"type": "string | undefined"
},
{
"name": "realm",
"attribute": "realm",
"type": "String",
"description": "Server issued realm for Digest authorization.\n\nUsed in the following types:\n- Digest"
},
{
"name": "nonce",
"attribute": "nonce",
"type": "String",
"description": "Server issued nonce for Digest authorization.\n\nUsed in the following types:\n- Digest"
},
{
"name": "algorithm",
"attribute": "algorithm",
"type": "String",
"description": "The algorithm used to hash the response for Digest authorization.\nIt can be either `MD5` or `MD5-sess`.\n\nUsed in the following types:\n- Digest"
"description": "The algorithm used to hash the response for Digest authorization.\n\nIt can be either `MD5` or `MD5-sess`.\n\nUsed in the following types:\n- Digest",
"type": "string"
},

@@ -104,4 +326,4 @@ {

"attribute": "qop",
"type": "String",
"description": "The quality of protection value for the digest response.\nIt can be either (empty), `auth`, or `auth-int`.\n\nUsed in the following types:\n- Digest"
"description": "The quality of protection value for the digest response.\nEither '', 'auth' or 'auth-int'\n\nUsed in the following types:\n- Digest",
"type": "string"
},

@@ -111,5 +333,4 @@ {

"attribute": "nc",
"type": "Number",
"description": "Nonce count - increments with each request used with the same nonce.\n\nUsed in the following types:\n- Digest",
"default": 1
"description": "Nonce count - increments with each request used with the same nonce\n\nUsed in the following types:\n- Digest",
"type": "number"
},

@@ -119,4 +340,4 @@ {

"attribute": "cnonce",
"type": "String",
"description": "Client nonce.\n\nUsed in the following types:\n- Digest"
"description": "Client nonce\n\nUsed in the following types:\n- Digest",
"type": "string"
},

@@ -126,10 +347,16 @@ {

"attribute": "opaque",
"type": "String",
"description": "A string of data specified by the server.\n\nUsed in the following types:\n- Digest"
"description": "A string of data specified by the server\n\nUsed in the following types:\n- Digest",
"type": "string"
},
{
"name": "response",
"attribute": "response",
"description": "Hashed response to server challenge\n\nUsed in the following types:\n- Digest",
"type": "string"
},
{
"name": "httpMethod",
"attribute": "httpmethod",
"type": "String",
"description": "Request HTTP method.\n\nUsed in the following types:\n- Digest"
"attribute": "httpMethod",
"description": "Request HTTP method\n\nUsed in the following types:\n- Digest",
"type": "string"
},

@@ -139,4 +366,4 @@ {

"attribute": "requestUrl",
"type": "String",
"description": "Current request URL.\n\nUsed in the following types:\n- Digest"
"description": "Current request URL.\n\nUsed in the following types:\n- Digest",
"type": "string"
},

@@ -146,16 +373,193 @@ {

"attribute": "requestBody",
"type": "String",
"description": "Current request body.\n\nUsed in the following types:\n- Digest"
"description": "Current request body.\n\nUsed in the following types:\n- Digest",
"type": "string"
},
{
"name": "consumerKey",
"attribute": "consumerKey",
"description": "Used by OAuth 1",
"type": "string"
},
{
"name": "consumerSecret",
"attribute": "consumerSecret",
"description": "Used by OAuth 1",
"type": "string"
},
{
"name": "token",
"attribute": "token",
"description": "Used by OAuth 1",
"type": "string"
},
{
"name": "tokenSecret",
"attribute": "tokenSecret",
"description": "Used by OAuth 1",
"type": "string"
},
{
"name": "timestamp",
"attribute": "timestamp",
"description": "Used by OAuth 1",
"type": "string"
},
{
"name": "nonce",
"attribute": "nonce",
"description": "Server issued nonce for Digest authorization.\n\nUsed in the following types:\n- Digest\n- OAuth 1",
"type": "string"
},
{
"name": "realm",
"attribute": "realm",
"description": "Server issued realm for Digest authorization.\n\nUsed in the following types:\n- Digest",
"type": "string"
},
{
"name": "signatureMethod",
"attribute": "signatureMethod",
"description": "Used by OAuth 1",
"type": "string"
},
{
"name": "requestTokenUri",
"attribute": "requestTokenUri",
"description": "Used by OAuth 1",
"type": "string"
},
{
"name": "authTokenMethod",
"attribute": "authTokenMethod",
"description": "Used by OAuth 1",
"type": "string"
},
{
"name": "authParamsLocation",
"attribute": "authParamsLocation",
"description": "Used by OAuth 1",
"type": "string"
},
{
"name": "signatureMethods",
"description": "Used by OAuth 1",
"type": "string[]"
},
{
"name": "isCustomResponseType",
"type": "boolean"
},
{
"name": "clientIdRequired",
"type": "boolean"
},
{
"name": "oauth2ClientSecretRendered",
"type": "boolean"
},
{
"name": "oauth2AuthorizationUriRendered",
"type": "boolean"
},
{
"name": "oauth2AccessTokenUriRendered",
"type": "boolean"
},
{
"name": "oauth2PasswordRendered",
"type": "boolean"
},
{
"name": "responseType",
"attribute": "responseType",
"description": "Selected authorization grand type.",
"type": "string"
},
{
"name": "clientId",
"attribute": "clientId",
"description": "The client ID for the auth token.",
"type": "string"
},
{
"name": "clientSecret",
"attribute": "clientSecret",
"description": "The client secret. It to be used when selected server flow.",
"type": "string"
},
{
"name": "scopes",
"description": "List of user selected scopes.\nIt can be pre-populated with list of scopes (array of strings).",
"type": "string[]"
},
{
"name": "allowedScopes",
"description": "List of pre-defined scopes to choose from. It will be passed to the `oauth2-scope-selector`\nelement.",
"type": "string[]"
},
{
"name": "preventCustomScopes",
"attribute": "preventCustomScopes",
"description": "If true then the `oauth2-scope-selector` will disallow to add a scope that is not\nin the `allowedScopes` list. Has no effect if the `allowedScopes` is not set.",
"type": "boolean"
},
{
"name": "accessToken",
"attribute": "accessToken",
"description": "When the user authorized the app it should be set to the token value.\nThis element do not perform authorization. Other elements must intercept\nthe token request event and perform the authorization.",
"type": "string"
},
{
"name": "tokenType",
"attribute": "tokenType",
"description": "By default it is \"bearer\" as the only one defined in OAuth 2.0 spec.\nIf the token response contains `tokenType` property then this value is updated.",
"type": "string | undefined"
},
{
"name": "responseTypes",
"description": "Currently available response types.",
"type": "ResponseType[] | undefined"
},
{
"name": "advanced",
"attribute": "advanced",
"description": "If set it renders authorization url, token url and scopes as advanced options\nwhich are then invisible by default. User can oen setting using the UI.",
"type": "boolean | undefined"
},
{
"name": "advancedOpened",
"attribute": "advancedOpened",
"description": "If true then the advanced options are opened.",
"type": "boolean | undefined"
},
{
"name": "noResponseType",
"attribute": "noResponseType",
"description": "If set, the response type selector is hidden from the UI.",
"type": "boolean | undefined"
},
{
"name": "oauthDeliveryMethod",
"attribute": "oauthDeliveryMethod",
"description": "Informs about what filed of the authenticated request the token property should be set.\nBy default the value is `header` which corresponds to the `authorization` by default,\nbut it is configured by the `deliveryName` property.\n\nThis can be used by the AMF model when the API spec defines where the access token should be\nput in the authenticated request.",
"type": "\"header\" | \"query\" | \"body\" | undefined",
"default": "\"header\""
},
{
"name": "oauthDeliveryName",
"attribute": "oauthDeliveryName",
"description": "The name of the authenticated request property that carries the token.\nBy default it is `authorization` which corresponds to `header` value of the `deliveryMethod` property.\n\nBy setting both `deliveryMethod` and `deliveryName` you instruct the application (assuming it reads this values)\nwhere to put the authorization token.",
"type": "string | undefined",
"default": "\"authorization\""
},
{
"name": "baseUri",
"attribute": "baseUri",
"type": "String",
"description": "A base URI to use to construct correct URLs to authorization endpoints. The UI will present authorization endpoints as provided by the user or attributes. However, if the paths are relative (must start with '/') then base URI is added to the path."
"description": "The base URI to use to construct the correct URLs to the authorization endpoints.\n\nWhen the paths are relative then base URI is added to the path.\nRelative paths must start with '/'.\n\nNote, URL processing is happening internally in the component. The produced authorize event\nwill have base URI already applied.",
"type": "string | undefined"
},
{
"name": "token",
"attribute": "token",
"type": "String",
"description": "Oauth 1 or Bearer token (from the oauth console or received from auth server). \n\nUsed in the following types:\n- OAuth 1\n- bearer"
"name": "lastErrorMessage",
"description": "The error message returned by the authorization library.\nIt renders error dialog when an error ocurred. \nIt is automatically cleared when the user request the token again.",
"type": "string | undefined"
}

@@ -166,20 +570,7 @@ ],

"name": "change",
"description": "Dispatched when change ocurred. The event is dispatched synchronously but the change cannot be canceled. It does not contain the 'detail' object with parameters. Call the `serialize()` function or get the properties manually for current type."
"description": "When authorization state change"
}
],
"slots": [],
"cssProperties": [
{
"name": "--authorization-method-oauth2-redirect-info-color",
"description": "Color of the redirect URI block in OAuth2 type panel.",
"default": "rgba(0, 0, 0, 0.74)"
},
{
"name": "--authorization-method-oauth2-redirect-info-background-color",
"description": "Background color of the redirect URI block in OAuth2 type panel.",
"default": "rgba(0, 0, 0, 0.12)"
}
]
}
]
}
}

17

index.d.ts

@@ -1,15 +0,2 @@

/**
* DO NOT EDIT
*
* This file was automatically generated by
* https://github.com/Polymer/tools/tree/master/packages/gen-typescript-declarations
*
* To modify these typings, edit the source file(s):
* index.js
*/
// tslint:disable:variable-name Describing an API that's defined elsewhere.
export {AuthorizationMethod} from './src/AuthorizationMethod.js';
export {AuthorizationMethod} from './src/AuthorizationMethod';
export {

@@ -22,2 +9,2 @@ METHOD_BASIC,

METHOD_OAUTH2,
} from './src/Utils.js';
} from './src/Utils';
{
"name": "@advanced-rest-client/authorization-method",
"description": "An element to render an UI for various authorization methods",
"version": "0.1.15",
"version": "0.2.0",
"license": "Apache-2.0",

@@ -21,3 +21,3 @@ "main": "index.js",

"contributors": [
"The Advanced REST client authors <arc@mulesoft.com>"
"Your name can be here!"
],

@@ -33,38 +33,44 @@ "repository": {

"dependencies": {
"@advanced-rest-client/arc-icons": "^3.1.0",
"@advanced-rest-client/arc-events": "^0.2.3",
"@advanced-rest-client/arc-icons": "^3.1.2",
"@advanced-rest-client/arc-types": "^0.2.14",
"@advanced-rest-client/clipboard-copy": "^3.0.1",
"@advanced-rest-client/events-target-mixin": "^3.2.0",
"@advanced-rest-client/oauth2-scope-selector": "^3.0.4",
"@advanced-rest-client/events-target-mixin": "^3.2.3",
"@advanced-rest-client/oauth2-scope-selector": "^4.0.0",
"@anypoint-web-components/anypoint-button": "^1.1.1",
"@anypoint-web-components/anypoint-dropdown-menu": "^0.1.14",
"@anypoint-web-components/anypoint-input": "^0.2.15",
"@anypoint-web-components/anypoint-item": "^1.0.5",
"@anypoint-web-components/anypoint-listbox": "^1.1.0",
"@anypoint-web-components/anypoint-switch": "^0.1.3",
"@open-wc/dedupe-mixin": "^1.2.17",
"@anypoint-web-components/anypoint-checkbox": "^1.1.3",
"@anypoint-web-components/anypoint-dropdown-menu": "^0.1.17",
"@anypoint-web-components/anypoint-input": "^0.2.22",
"@anypoint-web-components/anypoint-item": "^1.0.8",
"@anypoint-web-components/anypoint-listbox": "^1.1.5",
"@anypoint-web-components/anypoint-switch": "^0.1.4",
"@open-wc/dedupe-mixin": "^1.3.0",
"@polymer/paper-spinner": "^3.0.2",
"lit-element": "^2.3.1",
"lit-html": "^1.2.1"
"lit-element": "^2.4.0",
"lit-html": "^1.3.0"
},
"peerDependencies": {
"cryptojslib": "^3.1.2",
"jsrsasign": "^10.0.5"
},
"devDependencies": {
"@advanced-rest-client/arc-demo-helper": "^2.1.4",
"@advanced-rest-client/oauth-authorization": "^4.0.2",
"@advanced-rest-client/testing-karma-sl": "^1.3.1",
"@anypoint-web-components/anypoint-checkbox": "^1.0.2",
"@anypoint-web-components/anypoint-radio-button": "^0.1.4",
"@open-wc/eslint-config": "^2.0.0",
"@open-wc/testing": "^2.5.16",
"@open-wc/testing-karma": "^3.3.27",
"@advanced-rest-client/arc-demo-helper": "^2.2.0",
"@advanced-rest-client/oauth-authorization": "^5.0.0",
"@anypoint-web-components/anypoint-radio-button": "^0.1.6",
"@esm-bundle/chai": "^4.1.5",
"@open-wc/eslint-config": "^4.0.1",
"@open-wc/testing": "^2.5.32",
"@web/test-runner": "^0.9.7",
"@web/test-runner-playwright": "^0.6.4",
"@polymer/iron-test-helpers": "^3.0.0",
"cryptojslib": "^3.1.2",
"deepmerge": "^4.2.1",
"es-dev-server": "^1.50.5",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.11.0",
"husky": "^4.2.5",
"jsrsasign": "^8.0.15",
"lint-staged": "^10.2.2",
"prettier": "^2.0.5",
"sinon": "^9.0.2",
"typescript": "^3.9.2",
"es-dev-server": "^1.57.8",
"eslint": "^7.13.0",
"eslint-config-prettier": "^6.15.0",
"husky": "^4.3.0",
"jsrsasign": "^10.0.5",
"lint-staged": "^10.5.1",
"sinon": "^9.2.1",
"typescript": "^4.0.5",
"typescript-lit-html-plugin": "^0.9.0"

@@ -76,10 +82,8 @@ },

"format:eslint": "eslint --ext .js,.html . --fix --ignore-path .gitignore",
"lint:prettier": "prettier \"**/*.js\" --check --ignore-path .gitignore",
"format:prettier": "prettier \"**/*.js\" --write --ignore-path .gitignore",
"lint:types": "tsc",
"lint": "npm run lint:eslint && npm run lint:prettier",
"format": "npm run format:eslint && npm run format:prettier",
"test": "karma start --coverage",
"test:watch": "karma start --auto-watch=true --single-run=false",
"test:sl": "karma start karma.sl.config.js --compatibility auto --coverage"
"lint": "npm run lint:eslint",
"format": "npm run format:eslint",
"test": "web-test-runner test/**/*.test.js --coverage --node-resolve --playwright --browsers chromium firefox webkit",
"test:watch": "web-test-runner test/**/*.test.js --node-resolve --watch",
"gen:wc": "wca analyze \"*.js\" --outFile custom-elements.json"
},

@@ -95,2 +99,3 @@ "eslintConfig": {

"**/demo/**/*.js",
"**/test/**/*.js",
"**/demo/**/*.html"

@@ -108,6 +113,2 @@ ],

},
"prettier": {
"singleQuote": true,
"arrowParens": "always"
},
"husky": {

@@ -120,7 +121,5 @@ "hooks": {

"*.js": [
"eslint --fix",
"prettier --write",
"git add"
"eslint --fix"
]
}
}

@@ -0,1 +1,3 @@

# authorization-method custom element
[![Published on NPM](https://img.shields.io/npm/v/@advanced-rest-client/authorization-method.svg)](https://www.npmjs.com/package/@advanced-rest-client/authorization-method)

@@ -5,4 +7,6 @@

# authorization-method custom element
Note, in version 0.2.0 the API surface, data types, and events has changed.
Also the `oauth 1` type is now deprecated and will be removed from this element.
## Introduction

@@ -37,8 +41,8 @@

- basic authorization
- bearer token
- digest authorization
- NTLM
- OAuth 1
- OAuth 2
- basic authorization
- bearer token
- digest authorization
- NTLM
- OAuth 1
- OAuth 2

@@ -133,4 +137,4 @@ Other authorization methods can be added by extending `AuthorizationMethod` or `AuthorizationBase` class.

algorithm="MD5"
requesturl="https://api.domain.com/v0/endpoint"
httpmethod="GET"
requestUrl="https://api.domain.com/v0/endpoint"
httpMethod="GET"
></authorization-method>

@@ -144,11 +148,11 @@ ```

type="oauth 1"
consumerkey="key"
consumersecret="secret"
redirecturi="https://auth.api.com/rdr"
consumerKey="key"
consumerSecret="secret"
redirectUri="https://auth.api.com/rdr"
token="oauth 1 token"
tokenSecret="oauth 1 token secret"
requesttokenuri="http://auth.api.com/request_token.php"
accesstokenuri="http://tauth.api.com/access_token.php"
authtokenmethod="GET"
authparamslocation="querystring"
requestTokenUri="http://auth.api.com/request_token.php"
accessTokenUri="http://tauth.api.com/access_token.php"
authTokenMethod="GET"
authParamsLocation="querystring"
></authorization-method>

@@ -167,3 +171,3 @@ ```

clientId="client id"
clientsecret="client secret"
clientSecret="client secret"
scopes='["profile", "email"]'

@@ -184,4 +188,4 @@ ></authorization-method>

- `clientId`
- `authorizationUri`
- `clientId`
- `authorizationUri`

@@ -194,6 +198,6 @@ #### Authorization code grant

- `clientId`
- `clientSecret`
- `authorizationUri`
- `accessTokenUri`
- `clientId`
- `clientSecret`
- `authorizationUri`
- `accessTokenUri`

@@ -206,3 +210,3 @@ #### Client credentials grant

- `accessTokenUri`
- `accessTokenUri`

@@ -215,5 +219,5 @@ #### Password grant

- `accessTokenUri`
- `username`
- `password`
- `accessTokenUri`
- `username`
- `password`

@@ -226,11 +230,11 @@ #### Custom grant

- `accessTokenUri`
- `accessTokenUri`
### baseUri property
The component has `baseUri` property (`baseuri` attribute) that should be set to compute absolute value for the following URL values:
The component has `baseUri` property (`baseUri` attribute) that should be set to compute absolute value for the following URL values:
- `authorizationUri`
- `redirectUri`
- `accessTokenUri`
- `authorizationUri`
- `redirectUri`
- `accessTokenUri`

@@ -237,0 +241,0 @@ If any property above has a value that can be a relative path to any of the authorization endpoints and it starts with `/` character then the `baseUri` value is added as a prefix when constructing the serialized configuration object.

@@ -13,2 +13,6 @@ import { LitElement, CSSResult, TemplateResult } from 'lit-element';

export declare interface AuthorizationMethod extends Oauth2MethodMixin, Oauth1MethodMixin, DigestMethodMixin, BearerMethodMixin, BasicMethodMixin, NtlmMethodMixin, EventsTargetMixin, LitElement {
nonce: string;
new (): AuthorizationMethod;
prototype: AuthorizationMethod;
}

@@ -21,8 +25,10 @@

*
* The element mixes in multimple mixins from `src/` directory.
* The element mixes in multiple mixins from `src/` directory.
* Each mixin support an authorization method. When selection change (the `type`
* property) a render function from correcponding mixin is called.
* property) a render function from corresponding mixin is called.
*
* @fires change When authorization state change
*/
export declare class AuthorizationMethod {
readonly styles: CSSResult;
get styles(): CSSResult;

@@ -46,2 +52,3 @@ /**

* See readme file for detailed list of properties depending on selected type.
* @attribute
*/

@@ -51,2 +58,3 @@ type: string;

* When set the editor is in read only mode.
* @attribute
*/

@@ -56,2 +64,3 @@ readOnly: boolean;

* When set the inputs are disabled
* @attribute
*/

@@ -61,2 +70,3 @@ disabled: boolean;

* Enables compatibility with Anypoint components.
* @attribute
*/

@@ -66,2 +76,3 @@ compatibility: boolean;

* Enables Material Design outlined style
* @attribute
*/

@@ -71,2 +82,3 @@ outlined: boolean;

* Renders mobile friendly view.
* @attribute
*/

@@ -80,12 +92,202 @@ narrow: boolean;

*/
readonly authorizing: Boolean|null;
_authorizing: Boolean|null;
readonly authorizing: boolean|null;
_authorizing: boolean|null;
/**
* @attribute
*/
username: string;
/**
* @attribute
*/
password: string;
username: string;
/**
* @attribute
*/
redirectUri: string;
/**
* @attribute
*/
accessTokenUri: string;
/**
* @attribute
*/
authorizationUri: string;
/**
* @attribute
*/
token: string;
onchange: EventListener|null;
/**
* Server issued realm for Digest authorization.
*
* Used in the following types:
* - Digest
*
* @attribute
*/
realm: string;
/**
* Server issued nonce for Digest authorization.
*
* Used in the following types:
* - Digest
* - OAuth 1
*
* @attribute
*/
nonce: string;
/**
* The algorithm used to hash the response for Digest authorization.
*
* It can be either `MD5` or `MD5-sess`.
*
* Used in the following types:
* - Digest
*
* @attribute
*/
algorithm: string;
/**
* The quality of protection value for the digest response.
* Either '', 'auth' or 'auth-int'
*
* Used in the following types:
* - Digest
*
* @attribute
*/
qop: string;
/**
* Nonce count - increments with each request used with the same nonce
*
* Used in the following types:
* - Digest
*
* @attribute
*/
nc: number;
/**
* Client nonce
*
* Used in the following types:
* - Digest
*
* @attribute
*/
cnonce: string;
/**
* A string of data specified by the server
*
* Used in the following types:
* - Digest
*
* @attribute
*/
opaque: string;
/**
* Hashed response to server challenge
*
* Used in the following types:
* - Digest
*
* @attribute
*/
response: string;
/**
* Request HTTP method
*
* Used in the following types:
* - Digest
*
* @attribute
*/
httpMethod: string;
/**
* Current request URL.
*
* Used in the following types:
* - Digest
*
* @attribute
*/
get requestUrl(): string;
set requestUrl(value: string);
_requestUri: string;
/**
* Current request body.
*
* Used in the following types:
* - Digest
*
* @attribute
*/
requestBody: string;
/**
* Authorization domain
*
* Used in the following types:
* - NTLM
* @attribute
*/
domain?: string;
/**
* Used by OAuth 1
* @attribute
*/
consumerKey: string;
/**
* Used by OAuth 1
* @attribute
*/
consumerSecret: string;
/**
* Used by OAuth 1
* @attribute
*/
tokenSecret: string;
/**
* Used by OAuth 1
* @attribute
*/
timestamp: string;
/**
* Used by OAuth 1
* @attribute
*/
signatureMethod: string;
/**
* Used by OAuth 1
* @attribute
*/
requestTokenUri: string;
/**
* Used by OAuth 1
* @attribute
*/
authTokenMethod: string;
/**
* Used by OAuth 1
* @attribute
*/
authParamsLocation: string;
/**
* Used by OAuth 1
*/
signatureMethods: string[];
constructor();

@@ -105,3 +307,3 @@ connectedCallback(): void;

*/
serialize(): object;
serialize(): any;

@@ -114,3 +316,3 @@ /**

*/
restore(settings: object): any;
restore(settings: any): any;

@@ -120,5 +322,12 @@ /**

*/
validate(): Boolean;
authorize(): any;
validate(): boolean;
/**
* For methods with asynchronous authorization, this functions
* calls the underlying authorize function and returns the authorization result.
*
* @returns A promise resolved to the authorization result that depends on the method, or null
* if the current method does not support async authorization.
* @throws {Error} When authorization error.
*/
authorize(): Promise<any|null>;
}

@@ -83,5 +83,5 @@ import { html, LitElement } from 'lit-element';

*
* The element mixes in multimple mixins from `src/` directory.
* The element mixes in multiple mixins from `src/` directory.
* Each mixin support an authorization method. When selection change (the `type`
* property) a render function from correcponding mixin is called.
* property) a render function from corresponding mixin is called.
*

@@ -188,3 +188,3 @@ * @extends LitElement

* An URI of authentication endpoint where the user should be redirected
* to auththorize the app. This endpoint initialized OAuth flow.
* to authorize the app. This endpoint initialized OAuth flow.
*

@@ -360,3 +360,3 @@ * Used in the following types:

* Validates current method.
* @return {Boolean} Valudation state for current authorization method.
* @return {boolean} Validation state for current authorization method.
*/

@@ -371,3 +371,3 @@ validate() {

*
* @param {Object} settings Depends on current type.
* @param {any} settings Depends on current type.
* @return {any}

@@ -396,9 +396,10 @@ */

/**
* This method only works for OAuth 1 and OAuth 2 authorization methods.
*
* Authorizes the user by starting OAuth flow.
*
* @return {any}
* For methods with asynchronous authorization, this functions
* calls the underlying authorize function and returns the authorization result.
*
* @returns {Promise<any|null>} A promise resolved to the authorization result that depends on the method, or null
* if the current method does not support async authorization.
* @throws {Error} When authorization error.
*/
authorize() {
async authorize() {
const type = normalizeType(this.type);

@@ -411,3 +412,3 @@ switch (type) {

default:
return undefined;
return null;
}

@@ -414,0 +415,0 @@ }

@@ -1,6 +0,9 @@

export const serializeBasicAuth: symbol;
export const restoreBasicAuth: symbol;
export const renderBasicAuth: symbol;
export const clearBasicAuth: symbol;
import { BasicAuthorization } from "@advanced-rest-client/arc-types/src/authorization/Authorization";
import { TemplateResult } from "lit-html";
export const serializeBasicAuth: unique symbol;
export const restoreBasicAuth: unique symbol;
export const renderBasicAuth: unique symbol;
export const clearBasicAuth: unique symbol;
declare function BasicMethodMixin<T extends new (...args: any[]) => {}>(base: T): T & BasicMethodMixinConstructor;

@@ -11,5 +14,24 @@ interface BasicMethodMixinConstructor {

interface BasicMethodMixin {}
interface BasicMethodMixin {
/**
* Clears basic auth settings
*/
[clearBasicAuth](): void;
/**
* Serialized input values
* @returns An object with user input
*/
[serializeBasicAuth](): BasicAuthorization;
/**
* Restores previously serialized Basic authentication values.
* @param settings Previously serialized values
*/
[restoreBasicAuth](settings: BasicAuthorization): void;
[renderBasicAuth](): TemplateResult;
}
export {BasicMethodMixinConstructor};
export {BasicMethodMixin};

@@ -7,2 +7,3 @@ import { html } from 'lit-element';

/** @typedef {import('./AuthorizationMethod').AuthorizationMethod} AuthorizationMethod */
/** @typedef {import('@advanced-rest-client/arc-types').Authorization} BasicAuthorization */

@@ -15,8 +16,2 @@ export const serializeBasicAuth = Symbol('serializeBasicAuth');

/**
* @typedef {Object} BasicParams
* @property {string} password - User password value
* @property {string} username - User name value
*/
/**
* @param {AuthorizationMethod} base

@@ -36,3 +31,3 @@ */

* Serialized input values
* @return {BasicParams} An object with user input
* @return {BasicAuthorization} An object with user input
*/

@@ -47,4 +42,4 @@ [serializeBasicAuth]() {

/**
* Resotrespreviously serialized Basic authentication values.
* @param {BasicParams} settings Previously serialized values
* Restores previously serialized Basic authentication values.
* @param {BasicAuthorization} settings Previously serialized values
*/

@@ -51,0 +46,0 @@ [restoreBasicAuth](settings) {

@@ -1,6 +0,9 @@

export const serializeBearerAuth: symbol;
export const restoreBearerAuth: symbol;
export const renderBearerAuth: symbol;
export const clearBearerAuth: symbol;
import { BearerAuthorization } from "@advanced-rest-client/arc-types/src/authorization/Authorization";
import { TemplateResult } from "lit-html";
export const serializeBearerAuth: unique symbol;
export const restoreBearerAuth: unique symbol;
export const renderBearerAuth: unique symbol;
export const clearBearerAuth: unique symbol;
declare function BearerMethodMixin<T extends new (...args: any[]) => {}>(base: T): T & BearerMethodMixinConstructor;

@@ -12,2 +15,20 @@ interface BearerMethodMixinConstructor {

interface BearerMethodMixin {
/**
* Clears Bearer auth settings
*/
[clearBearerAuth](): void;
/**
* Serialized input values
* @returns An object with user input
*/
[serializeBearerAuth](): BearerAuthorization;
/**
* Restores previously serialized Bearer authentication values.
* @param settings Previously serialized values
*/
[restoreBearerAuth](settings: BearerAuthorization): void;
[renderBearerAuth](): TemplateResult;
}

@@ -14,0 +35,0 @@

@@ -7,2 +7,3 @@ import { html } from 'lit-element';

/** @typedef {import('./AuthorizationMethod').AuthorizationMethod} AuthorizationMethod */
/** @typedef {import('@advanced-rest-client/arc-types').Authorization} BearerAuthorization */

@@ -15,7 +16,2 @@ export const serializeBearerAuth = Symbol('serializeBearerAuth');

/**
* @typedef {Object} BearerParams
* @property {string} token - Berarer token value
*/
/**
* @param {AuthorizationMethod} base

@@ -34,3 +30,3 @@ */

* Serialized input values
* @return {BearerParams} An object with user input
* @return {BearerAuthorization} An object with user input
*/

@@ -44,4 +40,4 @@ [serializeBearerAuth]() {

/**
* Resotrespreviously serialized Bearer authentication values.
* @param {BearerParams} settings Previously serialized values
* Restores previously serialized Bearer authentication values.
* @param {BearerAuthorization} settings Previously serialized values
*/

@@ -48,0 +44,0 @@ [restoreBearerAuth](settings) {

@@ -18,2 +18,4 @@ export const renderDigestAuth: symbol;

* - Digest
*
* @attribute
*/

@@ -28,2 +30,4 @@ realm: string;

* - OAuth 1
*
* @attribute
*/

@@ -39,2 +43,4 @@ nonce: string;

* - Digest
*
* @attribute
*/

@@ -49,2 +55,4 @@ algorithm: string;

* - Digest
*
* @attribute
*/

@@ -58,2 +66,4 @@ qop: string;

* - Digest
*
* @attribute
*/

@@ -67,2 +77,4 @@ nc: number;

* - Digest
*
* @attribute
*/

@@ -76,2 +88,4 @@ cnonce: string;

* - Digest
*
* @attribute
*/

@@ -85,2 +99,4 @@ opaque: string;

* - Digest
*
* @attribute
*/

@@ -94,2 +110,4 @@ response: string;

* - Digest
*
* @attribute
*/

@@ -103,2 +121,4 @@ httpMethod: string;

* - Digest
*
* @attribute
*/

@@ -114,2 +134,4 @@ requestUrl: string;

* - Digest
*
* @attribute
*/

@@ -116,0 +138,0 @@ requestBody: string;

@@ -9,2 +9,3 @@ import { html } from 'lit-element';

/** @typedef {import('./AuthorizationMethod').AuthorizationMethod} AuthorizationMethod */
/** @typedef {import('@advanced-rest-client/arc-types/src/authorization/Authorization').DigestAuthorization} DigestAuthorization */

@@ -39,19 +40,4 @@ export const renderDigestAuth = Symbol('renderDigestAuth');

/**
* @typedef {Object} DigestParams
* @property {string} password - User password value
* @property {string} username - User name value
* @property {string} realm
* @property {string} nonce
* @property {string} uri
* @property {string} qop
* @property {string} opaque
* @property {string} response
* @property {string|number} nc
* @property {string} cnonce
* @property {string} algorithm
* @param {AuthorizationMethod} base
*/
/**
* @param {typeof HTMLElement} base
*/
const mxFunction = (base) => {

@@ -160,2 +146,10 @@ class DigestMethodMixinImpl extends base {

constructor() {
super();
/**
* @type {string}
*/
this.httpMethod = undefined;
}
[_processRequestUrl](value) {

@@ -202,3 +196,3 @@ if (!value || typeof value !== 'string') {

this.algorithm = '';
this.nc = '';
this.nc = undefined;
this.response = '';

@@ -211,4 +205,4 @@ this[setDigestDefaults]();

/**
* Resotres previously serialized Digest authentication values.
* @param {DigestParams} settings Previously serialized values
* Restores previously serialized Digest authentication values.
* @param {DigestAuthorization} settings Previously serialized values
*/

@@ -234,3 +228,3 @@ [restoreDigestAuth](settings) {

* Serialized input values
* @return {DigestParams} An object with user input
* @return {DigestAuthorization} An object with user input
*/

@@ -261,3 +255,3 @@ [serializeDigestAuth]() {

*
* @return {String} A response part of the authenticated digest request.
* @return {string} A response part of the authenticated digest request.
*/

@@ -309,7 +303,7 @@ [_generateDigestResponse]() {

const { outlined, compatibility, readOnly, disabled, qop } = this;
return html`<anypoint-dropdown-menu
return html`
<anypoint-dropdown-menu
?outlined="${outlined}"
?compatibility="${compatibility}"
?readOnly="${readOnly}"
?disabled="${disabled}"
?disabled="${disabled||readOnly}"
name="qop"

@@ -322,6 +316,4 @@ >

@selected-changed="${this[selectionHandler]}"
?outlined="${outlined}"
?compatibility="${compatibility}"
?readOnly="${readOnly}"
?disabled="${disabled}"
?disabled="${disabled||readOnly}"
attrforselected="data-qop"

@@ -341,7 +333,7 @@ >

const { outlined, compatibility, readOnly, disabled, algorithm } = this;
return html`<anypoint-dropdown-menu
return html`
<anypoint-dropdown-menu
?outlined="${outlined}"
?compatibility="${compatibility}"
?readOnly="${readOnly}"
?disabled="${disabled}"
?disabled="${disabled||readOnly}"
name="algorithm"

@@ -354,6 +346,4 @@ >

@selected-changed="${this[selectionHandler]}"
?outlined="${outlined}"
?compatibility="${compatibility}"
?readOnly="${readOnly}"
?disabled="${disabled}"
?disabled="${disabled||readOnly}"
attrforselected="data-algorithm"

@@ -387,3 +377,4 @@ >

} = this;
return html` <form autocomplete="on" class="digest-auth">
return html`
<form autocomplete="on" class="digest-auth">
${inputTemplate('username', username, 'User name', this[inputHandler], {

@@ -473,6 +464,6 @@ required: true,

)}
${inputTemplate('cnonce', cnonce, 'Client nounce', this[inputHandler], {
${inputTemplate('cnonce', cnonce, 'Client nonce', this[inputHandler], {
required: true,
autoValidate: true,
invalidLabel: 'Client nounce is required',
invalidLabel: 'Client nonce is required',
classes: { block: true },

@@ -479,0 +470,0 @@ outlined,

@@ -1,6 +0,9 @@

export const serializeNtlmAuth: symbol;
export const restoreNtlmAuth: symbol;
export const renderNtlmAuth: symbol;
export const clearNtlmAuth: symbol;
import { NtlmAuthorization } from "@advanced-rest-client/arc-types/src/authorization/Authorization";
import { TemplateResult } from "lit-html";
export const serializeNtlmAuth: unique symbol;
export const restoreNtlmAuth: unique symbol;
export const renderNtlmAuth: unique symbol;
export const clearNtlmAuth: unique symbol;
declare function NtlmMethodMixin<T extends new (...args: any[]) => {}>(base: T): T & NtlmMethodMixinConstructor;

@@ -17,4 +20,24 @@ interface NtlmMethodMixinConstructor {

* - NTLM
* @attribute
*/
domain?: string;
/**
* Clears NTLM auth settings
*/
[clearNtlmAuth](): void;
/**
* Serialized input values
* @returns An object with user input
*/
[serializeNtlmAuth](): NtlmAuthorization;
/**
* Restores previously serialized NTLM authentication values.
* @param settings Previously serialized values
*/
[restoreNtlmAuth](settings: NtlmAuthorization): void;
[renderNtlmAuth](): TemplateResult;
}

@@ -21,0 +44,0 @@

@@ -7,2 +7,3 @@ import { html } from 'lit-element';

/** @typedef {import('./AuthorizationMethod').AuthorizationMethod} AuthorizationMethod */
/** @typedef {import('@advanced-rest-client/arc-types/src/authorization/Authorization').NtlmAuthorization} NtlmAuthorization */

@@ -15,9 +16,2 @@ export const serializeNtlmAuth = Symbol('serializeNtlmAuth');

/**
* @typedef {Object} NtlmParams
* @property {string} password - User password value
* @property {string} username - User name value
* @property {string} domain - NT domain
*/
/**
* @param {AuthorizationMethod} base

@@ -50,3 +44,3 @@ */

* Serialized input values
* @return {NtlmParams} An object with user input
* @return {NtlmAuthorization} An object with user input
*/

@@ -62,4 +56,4 @@ [serializeNtlmAuth]() {

/**
* Resotres previously serialized NTML authentication values.
* @param {NtlmParams} settings Previously serialized values
* Restores previously serialized NTLM authentication values.
* @param {NtlmAuthorization} settings Previously serialized values
*/

@@ -66,0 +60,0 @@ [restoreNtlmAuth](settings) {

@@ -1,7 +0,22 @@

export const setOauth1Defaults: symbol;
export const restoreOauth1Auth: symbol;
export const serializeOauth1Auth: symbol;
export const renderOauth1Auth: symbol;
export const clearOauth1Auth: symbol;
import { Authorization } from '@advanced-rest-client/arc-types';
import { TemplateResult } from 'lit-html';
export const setOauth1Defaults: unique symbol;
export const restoreOauth1Auth: unique symbol;
export const serializeOauth1Auth: unique symbol;
export const renderOauth1Auth: unique symbol;
export const clearOauth1Auth: unique symbol;
export const authorizeOauth1: unique symbol;
export const defaultSignatureMethods: string[];
export const oauth1ErrorHandler: unique symbol;
export const oauth1tokenResponseHandler: unique symbol;
export const genTimestamp: unique symbol;
export const timestampHandler: unique symbol;
export const genNonce: unique symbol;
export const nonceHandler: unique symbol;
export const oauth1TokenMethodTemplate: unique symbol;
export const oauth1ParamLocationTemplate: unique symbol;
export const oauth1TimestampTemplate: unique symbol;
export const oauth1NonceTemplate: unique symbol;
export const oauth1SignatureMethodsTemplate: unique symbol;

@@ -14,6 +29,26 @@ declare function Oauth1MethodMixin<T extends new (...args: any[]) => {}>(base: T): T & Oauth1MethodMixinConstructor;

interface Oauth1MethodMixin {
/**
* Used by OAuth 1
* @attribute
*/
consumerKey: string;
/**
* Used by OAuth 1
* @attribute
*/
consumerSecret: string;
/**
* Used by OAuth 1
* @attribute
*/
token: string;
/**
* Used by OAuth 1
* @attribute
*/
tokenSecret: string;
/**
* Used by OAuth 1
* @attribute
*/
timestamp: string;

@@ -28,9 +63,93 @@ /**

nonce: string;
/**
* Used by OAuth 1
* @attribute
*/
realm: string;
/**
* Used by OAuth 1
* @attribute
*/
signatureMethod: string;
/**
* Used by OAuth 1
* @attribute
*/
requestTokenUri: string;
/**
* Used by OAuth 1
* @attribute
*/
authTokenMethod: string;
/**
* Used by OAuth 1
* @attribute
*/
authParamsLocation: string;
/**
* Used by OAuth 1
*/
signatureMethods: string[];
_attachListeners(node: EventTarget): void;
_detachListeners(node: EventTarget): void;
[setOauth1Defaults](): void;
/**
* Clears OAuth 1 auth settings
*/
[clearOauth1Auth](): void;
/**
* Serialized input values
* @returns An object with user input
*/
[serializeOauth1Auth](): Authorization.OAuth1Authorization;
/**
* Restores previously serialized authentication values.
* @param settings Previously serialized values
*/
[restoreOauth1Auth](settings: Authorization.OAuth1Authorization): void;
/**
* Handles OAuth1 authorization errors.
*/
[oauth1ErrorHandler](): void;
/**
* Handler for the `oauth1-token-response` custom event.
* Sets `token` and `tokenSecret` properties from the event.
*/
[oauth1tokenResponseHandler](e: CustomEvent): void;
/**
* Sets timestamp in seconds
* @param ignoreChange Ignores change notification when set
*/
[genTimestamp](ignoreChange: boolean): void;
[timestampHandler](): void;
/**
* Sets auto-generated nonce
* @param {Boolean} ignoreChange Ignores change notification when set
*/
[genNonce](ignoreChange: boolean): void;
[nonceHandler](): void;
/**
* Sends the `oauth1-token-requested` event.
* @return True if event was sent. Can be false if event is not handled or when the form is invalid.
*/
[authorizeOauth1](): boolean;
[oauth1TokenMethodTemplate](): TemplateResult;
[oauth1ParamLocationTemplate](): TemplateResult;
[oauth1TimestampTemplate](): TemplateResult;
[oauth1NonceTemplate](): TemplateResult;
[oauth1SignatureMethodsTemplate](): TemplateResult;
[renderOauth1Auth](): TemplateResult;
authorize(): any;

@@ -37,0 +156,0 @@ }

@@ -10,16 +10,17 @@ import { html } from 'lit-element';

/** @typedef {import('./AuthorizationMethod').AuthorizationMethod} AuthorizationMethod */
/** @typedef {import('@advanced-rest-client/arc-types').Authorization.OAuth1Authorization} OAuth1Authorization */
/* eslint-disable no-plusplus */
const oauth1ErrorHandler = Symbol('oauth1ErrorHandler');
const oauth1tokenResponseHandler = Symbol('oauth1tokenResponseHandler');
const oauth1ParamLocationTemplate = Symbol('oauth1ParamLocationTemplate');
const oauth1TokenMethodTemplate = Symbol('oauth1TokenMethodTemplate');
const oauth1TimestampTemplate = Symbol('oauth1TimestampTemplate');
const oauth1NonceTemplate = Symbol('oauth1NonceTemplate');
const oauth1SignatureMethodsTemplate = Symbol('oauth1SignatureMethodsTemplate');
const timestampHandler = Symbol('timestampHandler');
const nonceHandler = Symbol('nonceHandler');
const genTimestamp = Symbol('genTimestamp');
const genNonce = Symbol('genNonce');
export const oauth1ErrorHandler = Symbol('oauth1ErrorHandler');
export const oauth1tokenResponseHandler = Symbol('oauth1tokenResponseHandler');
export const oauth1ParamLocationTemplate = Symbol('oauth1ParamLocationTemplate');
export const oauth1TokenMethodTemplate = Symbol('oauth1TokenMethodTemplate');
export const oauth1TimestampTemplate = Symbol('oauth1TimestampTemplate');
export const oauth1NonceTemplate = Symbol('oauth1NonceTemplate');
export const oauth1SignatureMethodsTemplate = Symbol('oauth1SignatureMethodsTemplate');
export const timestampHandler = Symbol('timestampHandler');
export const nonceHandler = Symbol('nonceHandler');
export const genTimestamp = Symbol('genTimestamp');
export const genNonce = Symbol('genNonce');
export const serializeOauth1Auth = Symbol('serializeOauth1Auth');

@@ -35,21 +36,2 @@ export const restoreOauth1Auth = Symbol('restoreOauth1Auth');

/**
* @typedef {Object} Oauth1Params
* @property {string} consumerKey
* @property {string} consumerSecret
* @property {string} token
* @property {string} tokenSecret
* @property {string|number} timestamp
* @property {string} nonce
* @property {string} realm
* @property {string} signatureMethod
* @property {string} requestTokenUri
* @property {string} accessTokenUri
* @property {string} redirectUri
* @property {string} authParamsLocation
* @property {string} authTokenMethod
* @property {string} authorizationUri
* @property {string} type - always set ot oauth1
*/
/**
* @param {AuthorizationMethod} base

@@ -209,2 +191,6 @@ */

this.authorizationUri = '';
/**
* @type {boolean}
*/
this._authorizing = false;
this[setOauth1Defaults]();

@@ -215,3 +201,3 @@ }

* Serialized input values
* @return {Oauth1Params} An object with user input
* @return {OAuth1Authorization} An object with user input
*/

@@ -239,4 +225,4 @@ [serializeOauth1Auth]() {

/**
* Resotres previously serialized authentication values.
* @param {Oauth1Params} settings Previously serialized values
* Restores previously serialized authentication values.
* @param {OAuth1Authorization} settings Previously serialized values
*/

@@ -248,3 +234,3 @@ [restoreOauth1Auth](settings) {

this.tokenSecret = settings.tokenSecret;
this.timestamp = settings.timestamp;
this.timestamp = /** @type string */ (settings.timestamp);
this.nonce = settings.nonce;

@@ -283,6 +269,7 @@ this.realm = settings.realm;

* Sets timestamp in seconds
* @param {Boolean} ignoreChange Ignores change bnotification when set
* @param {Boolean} ignoreChange Ignores change notification when set
*/
[genTimestamp](ignoreChange) {
const t = Math.floor(Date.now() / 1000);
// @ts-ignore
this.timestamp = t;

@@ -299,13 +286,13 @@ if (!ignoreChange) {

/**
* Sets autogenerated nocne
* @param {Boolean} ignoreChange Ignores change bnotification when set
* Sets autogenerated nonce
* @param {Boolean} ignoreChange Ignores change notification when set
*/
[genNonce](ignoreChange) {
const result = [];
const chrs =
const chars =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
const chrsLength = chrs.length;
const charsLength = chars.length;
const length = 32;
for (let i = 0; i < length; i++) {
result[result.length] = chrs[Math.floor(Math.random() * chrsLength)];
result[result.length] = chars[Math.floor(Math.random() * charsLength)];
}

@@ -414,4 +401,3 @@ this.nonce = result.join('');

?compatibility="${compatibility}"
?readOnly="${readOnly}"
?disabled="${disabled}"
?disabled="${disabled||readOnly}"
>

@@ -424,6 +410,4 @@ <label slot="label">Authorization token method</label>

data-name="authTokenMethod"
?outlined="${outlined}"
?compatibility="${compatibility}"
?readOnly="${readOnly}"
?disabled="${disabled}"
?disabled="${disabled||readOnly}"
attrforselected="data-value"

@@ -454,4 +438,3 @@ >

?compatibility="${compatibility}"
?readOnly="${readOnly}"
?disabled="${disabled}"
?disabled="${disabled||readOnly}"
>

@@ -464,6 +447,4 @@ <label slot="label">Oauth parameters location</label>

data-name="authParamsLocation"
?outlined="${outlined}"
?compatibility="${compatibility}"
?readOnly="${readOnly}"
?disabled="${disabled}"
?disabled="${disabled||readOnly}"
attrforselected="data-value"

@@ -489,3 +470,3 @@ >

required
autovalidate
autoValidate
name="timestamp"

@@ -500,3 +481,3 @@ .value="${timestamp}"

?disabled="${disabled}"
invalidmessage="Timestamp is required"
invalidMessage="Timestamp is required"
>

@@ -519,3 +500,3 @@ <label slot="label">Timestamp</label>

required
autovalidate
autoValidate
name="nonce"

@@ -530,3 +511,3 @@ .value="${nonce}"

?disabled="${disabled}"
invalidmessage="Nonce is required"
invalidMessage="Nonce is required"
>

@@ -559,4 +540,3 @@ <label slot="label">Nonce</label>

?compatibility="${compatibility}"
?readOnly="${readOnly}"
?disabled="${disabled}"
?disabled="${disabled||readOnly}"
>

@@ -569,6 +549,4 @@ <label slot="label">Signature method</label>

data-name="signatureMethod"
?outlined="${outlined}"
?compatibility="${compatibility}"
?readOnly="${readOnly}"
?disabled="${disabled}"
?disabled="${disabled||readOnly}"
attrforselected="data-value"

@@ -725,3 +703,3 @@ >

>
<paper-spinner .active="${_authorizing}"></paper-spinner>
<paper-spinner ?active="${_authorizing}"></paper-spinner>
</div>`;

@@ -728,0 +706,0 @@ }

@@ -1,2 +0,42 @@

declare interface GrantType {
import { TokenInfo, OAuth2Authorization } from "@advanced-rest-client/arc-types/src/authorization/Authorization";
import { TemplateResult } from "lit-html";
export type OAuth2DeliveryMethod = 'header' | 'query' | 'body';
export declare interface OAuth2Settings extends OAuth2Authorization {
/**
* The access token type. Default to `Bearer`
*/
tokenType?: string;
/**
* The last access token received from the authorization server.
*/
accessToken?: string;
/**
* Informs about what filed of the authenticated request the token property should be set.
* By default the value is `header` which corresponds to the `authorization` by default,
* but it is configured by the `deliveryName` property.
*
* This can be used by the AMF model when the API spec defines where the access token should be
* put in the authenticated request.
*
* @default header
*/
deliveryMethod: OAuth2DeliveryMethod;
/**
* The name of the authenticated request property that carries the token.
* By default it is `authorization` which corresponds to `header` value of the `deliveryMethod` property.
*
* By setting both `deliveryMethod` and `deliveryName` you instruct the application (assuming it reads this values)
* where to put the authorization token.
*
* @default authorization
*/
deliveryName: string;
}
export declare interface GrantType {
type: string;

@@ -6,12 +46,31 @@ label: string;

export const setOauth2Defaults: symbol;
export const authorizeOauth2: symbol;
export const renderOauth2Auth: symbol;
export const restoreOauth2Auth: symbol;
export const serializeOauth2Auth: symbol;
export const oauth2CustomPropertiesTemplate: symbol;
export const autoHide: symbol;
export const clearOauth2Auth: symbol;
export const oauth2GrantTypes: Array<GrantType>;
export const clickCopyAction: unique symbol;
export const scopesChanged: unique symbol;
export const oauth2RedirectTemplate: unique symbol;
export const oauth2GrantTypeTemplate: unique symbol;
export const oauth2AdvancedTemplate: unique symbol;
export const oath2AuthorizeTemplate: unique symbol;
export const oauth2TokenTemplate: unique symbol;
export const advHandler: unique symbol;
export const readUrlValue: unique symbol;
export const setOauth2Defaults: unique symbol;
export const authorizeOauth2: unique symbol;
export const renderOauth2Auth: unique symbol;
export const restoreOauth2Auth: unique symbol;
export const serializeOauth2Auth: unique symbol;
export const oauth2CustomPropertiesTemplate: unique symbol;
export const autoHide: unique symbol;
export const clearOauth2Auth: unique symbol;
export const clientIdTemplate: unique symbol;
export const clientSecretTemplate: unique symbol;
export const toggleAdvViewSwitchTemplate: unique symbol;
export const authorizationUriTemplate: unique symbol;
export const accessTokenUriTemplate: unique symbol;
export const usernameTemplate: unique symbol;
export const passwordTemplateLocal: unique symbol;
export const scopesTemplate: unique symbol;
export const pkceTemplate: unique symbol;
export const oauth2GrantTypes: GrantType[];
declare function Oauth2MethodMixin<T extends new (...args: any[]) => {}>(base: T): T & Oauth2MethodMixinConstructor;

@@ -23,3 +82,3 @@ interface Oauth2MethodMixinConstructor {

interface Oauth2MethodMixin {
readonly isCustomGrant: boolean;
readonly isCustomGrantType: boolean;
readonly clientIdRequired: boolean;

@@ -30,22 +89,261 @@ readonly oauth2ClientSecretRendered: boolean;

readonly oauth2PasswordRendered: boolean;
readonly lastState: string;
/**
* Selected authorization grand type.
* @attribute
*/
grantType: string;
/**
* The client ID for the auth token.
* @attribute
*/
clientId: string;
/**
* The client secret. It to be used when selected server flow.
* @attribute
*/
clientSecret: string;
/**
* List of user selected scopes.
* It can be pre-populated with list of scopes (array of strings).
*/
scopes: string[];
/**
* List of pre-defined scopes to choose from. It will be passed to the `oauth2-scope-selector`
* element.
*/
allowedScopes: string[];
/**
* If true then the `oauth2-scope-selector` will disallow to add a scope that is not
* in the `allowedScopes` list. Has no effect if the `allowedScopes` is not set.
* @attribute
*/
preventCustomScopes: boolean;
accessToken: boolean;
tokenType: boolean;
grantTypes: string[];
isAdvanced: boolean;
advancedOpened: boolean;
noGrantType: boolean;
oauthDeliveryMethod: string;
oauthDeliveryName: string;
baseUri: string;
_lastState: string;
/**
* When the user authorized the app it should be set to the token value.
* This element do not perform authorization. Other elements must intercept
* the token request event and perform the authorization.
* @attribute
*/
accessToken: string;
/**
* By default it is "bearer" as the only one defined in OAuth 2.0 spec.
* If the token response contains `tokenType` property then this value is updated.
* @attribute
*/
tokenType?: string;
/**
* Currently available response types.
*/
grantTypes?: GrantType[];
/**
* If set it renders authorization url, token url and scopes as advanced options
* which are then invisible by default. User can oen setting using the UI.
* @attribute
*/
advanced?: boolean;
/**
* If true then the advanced options are opened.
* @attribute
*/
advancedOpened?: boolean;
/**
* If set, the response type selector is hidden from the UI.
* @attribute
*/
noGrantType?: boolean;
/**
* Informs about what filed of the authenticated request the token property should be set.
* By default the value is `header` which corresponds to the `authorization` by default,
* but it is configured by the `deliveryName` property.
*
* This can be used by the AMF model when the API spec defines where the access token should be
* put in the authenticated request.
*
* @default header
* @attribute
*/
oauthDeliveryMethod?: OAuth2DeliveryMethod;
/**
* The name of the authenticated request property that carries the token.
* By default it is `authorization` which corresponds to `header` value of the `deliveryMethod` property.
*
* By setting both `deliveryMethod` and `deliveryName` you instruct the application (assuming it reads this values)
* where to put the authorization token.
*
* @default authorization
* @attribute
*/
oauthDeliveryName?: string;
/**
* The base URI to use to construct the correct URLs to the authorization endpoints.
*
* When the paths are relative then base URI is added to the path.
* Relative paths must start with '/'.
*
* Note, URL processing is happening internally in the component. The produced authorize event
* will have base URI already applied.
* @attribute
*/
baseUri?: string;
/**
* The error message returned by the authorization library.
* It renders error dialog when an error ocurred.
* It is automatically cleared when the user request the token again.
*/
lastErrorMessage?: string;
/**
* When this property is set then the PKCE option is not rendered for the
* `authorization_code`. This is mainly meant to be used by the `api-authorization-method`
* to keep this control disabled and override generated settings when the API spec
* says that the PKCE is supported.
* @attribute
*/
noPkce?: boolean;
/**
* Whether or not the PKCE extension is enabled for this authorization configuration.
* Note, PKCE, per the spec, is only available for `authorization_code` grantType.
* @attribute
*/
pkce: boolean,
/**
* Restores previously serialized values
* @param settings
*/
[restoreOauth2Auth](settings: OAuth2Settings): void;
authorize(): any;
/**
* Serializes OAuth2 parameters into a configuration object.
*/
[serializeOauth2Auth](): OAuth2Settings;
/**
* When defined and the `url` is a relative path staring with `/` then it
* adds base URI to the path and returns concatenated value.
*
* @return The final URL value.
*/
[readUrlValue](url: string): string;
[setOauth2Defaults](): void;
/**
* Clears OAuth 1 auth settings
*/
[clearOauth2Auth](): void;
/**
* Performs the authorization.
*
* @returns The auth token or null if couldn't be requested.
* @throws {Error} When authorization error
*/
[authorizeOauth2](): Promise<TokenInfo|null>;
/**
* Generates `state` parameter for the OAuth2 call.
*
* @return {string} Generated state string.
*/
generateState(): string;
/**
* This function hides all non-crucial fields that has been pre-filled when element has been
* initialize (values not provided by the user). Hidden fields will be available under
* "advanced" options.
*
* To prevent this behavior set `no-auto` attribute on this element.
*/
[autoHide](): void;
/**
* A handler for `focus` event on a label that contains text and
* should be copied to clipboard when user is interacting with it.
*/
[clickCopyAction](e: MouseEvent): void;
/**
* Event handler for the scopes element changed state
*/
[scopesChanged](e: CustomEvent): void;
[advHandler](e: CustomEvent): void;
/**
* @returns The template for the OAuth 2 redirect URI label
*/
[oauth2RedirectTemplate](): TemplateResult;
/**
* @returns The template for the OAuth 2 response type selector
*/
[oauth2GrantTypeTemplate](): TemplateResult;
/**
* @returns The template for the OAuth 2 advanced options.
*/
[oauth2AdvancedTemplate](): TemplateResult;
/**
* @returns The template for the "authorize" button.
*/
[oath2AuthorizeTemplate](): TemplateResult;
/**
* @returns The template for the OAuth 2 token value
*/
[oauth2TokenTemplate](): TemplateResult;
/**
* @returns The template for the OAuth 2 editor.
*/
[renderOauth2Auth](): TemplateResult;
[oauth2CustomPropertiesTemplate](): TemplateResult|string;
/**
* @returns The template for the OAuth 2 client secret input.
*/
[clientSecretTemplate](): TemplateResult|string;
/**
* @returns The template for the OAuth 2 client id input.
*/
[clientIdTemplate](): TemplateResult;
/**
* @returns The template for the toggle advanced view switch
*/
[toggleAdvViewSwitchTemplate](): TemplateResult|string;
/**
* @param urlType The input type to render
* @returns The template for the authorization URI input
*/
[authorizationUriTemplate](urlType: string): TemplateResult|string;
/**
* @param urlType The input type to render
* @returns The template for the access token URI input
*/
[accessTokenUriTemplate](urlType: string): TemplateResult|string;
/**
* @returns The template for the user name input
*/
[usernameTemplate](): TemplateResult|string;
/**
* @returns The template for the user password input
*/
[passwordTemplateLocal](): TemplateResult|string;
/**
* @returns The template for the OAuth 2 scopes input
*/
[scopesTemplate](): TemplateResult;
/**
* @returns The template for the PKCE option of the OAuth 2 extension.
*/
[pkceTemplate](): TemplateResult|string;
}

@@ -52,0 +350,0 @@

@@ -0,5 +1,8 @@

/* eslint-disable lit-a11y/click-events-have-key-events */
import { html } from 'lit-element';
import { dedupeMixin } from '@open-wc/dedupe-mixin';
import { AuthorizationEvents } from '@advanced-rest-client/arc-events';
import '@advanced-rest-client/oauth2-scope-selector/oauth2-scope-selector.js';
import '@anypoint-web-components/anypoint-switch/anypoint-switch.js';
import '@anypoint-web-components/anypoint-checkbox/anypoint-checkbox.js';
import { notifyChange, selectionHandler, inputHandler } from './Utils.js';

@@ -9,2 +12,8 @@ import { passwordTemplate, inputTemplate } from './CommonTemplates.js';

/** @typedef {import('./AuthorizationMethod').AuthorizationMethod} AuthorizationMethod */
/** @typedef {import('./Oauth2MethodMixin').GrantType} GrantType */
/** @typedef {import('./Oauth2MethodMixin').OAuth2Settings} OAuth2Settings */
/** @typedef {import('@advanced-rest-client/arc-types').Authorization.TokenInfo} TokenInfo */
/** @typedef {import('@advanced-rest-client/oauth2-scope-selector').OAuth2ScopeSelector} OAuth2ScopeSelector */
/** @typedef {import('lit-element').TemplateResult} TemplateResult */
/** @typedef {import('@anypoint-web-components/anypoint-checkbox').AnypointCheckbox} AnypointCheckbox */

@@ -16,14 +25,11 @@ /* eslint-disable no-plusplus */

/** Functions */
const _oauth2ErrorHandler = Symbol('oauth2ErrorHandler');
const _tokenSuccessHandler = Symbol('tokenSuccessHandler');
const _clickCopyAction = Symbol('clickCopyAction');
const _scopesChanged = Symbol('scopesChanged');
const _oauth2RedirectTemplate = Symbol('oauth2RedirectTemplate');
const _oauth2GrantTypeTemplate = Symbol('oauth2GrantTypeTemplate');
const _oauth2AdvancedTemplate = Symbol('oauth2AdvancedTemplate');
const _oath2AuthorizeTemplate = Symbol('oath2AuthorizeTemplate');
const _oauth2TokenTemplate = Symbol('oauth2TokenTemplate');
const _advHandler = Symbol('advHandler');
const readUrlValue = Symbol('readUrlValue');
export const clickCopyAction = Symbol('clickCopyAction');
export const scopesChanged = Symbol('scopesChanged');
export const oauth2RedirectTemplate = Symbol('oauth2RedirectTemplate');
export const oauth2GrantTypeTemplate = Symbol('oauth2GrantTypeTemplate');
export const oauth2AdvancedTemplate = Symbol('oauth2AdvancedTemplate');
export const oath2AuthorizeTemplate = Symbol('oath2AuthorizeTemplate');
export const oauth2TokenTemplate = Symbol('oauth2TokenTemplate');
export const advHandler = Symbol('advHandler');
export const readUrlValue = Symbol('readUrlValue');
export const setOauth2Defaults = Symbol('setOauth2Defaults');

@@ -34,13 +40,21 @@ export const authorizeOauth2 = Symbol('authorizeOauth2');

export const serializeOauth2Auth = Symbol('serializeOauth2Auth');
export const oauth2CustomPropertiesTemplate = Symbol(
'oauth2CustomPropertiesTemplate'
);
export const oauth2CustomPropertiesTemplate = Symbol('oauth2CustomPropertiesTemplate');
export const autoHide = Symbol('autoHide');
export const clearOauth2Auth = Symbol('clearOauth2Auth');
export const clientIdTemplate = Symbol('clientIdTemplate');
export const clientSecretTemplate = Symbol('clientSecretTemplate');
export const toggleAdvViewSwitchTemplate = Symbol('toggleAdvViewSwitchTemplate');
export const authorizationUriTemplate = Symbol('authorizationUriTemplate');
export const accessTokenUriTemplate = Symbol('accessTokenUriTemplate');
export const usernameTemplate = Symbol('usernameTemplate');
export const passwordTemplateLocal = Symbol('passwordTemplateLocal');
export const scopesTemplate = Symbol('scopesTemplate');
export const pkceTemplate = Symbol('pkceTemplate');
export const pkceChangeHandler = Symbol('pkceChangeHandler');
/**
* List of OAuth 2.0 default grant types.
* List of OAuth 2.0 default response types.
* This list can be extended by custom grants
*
* @return {Array<Object>} List of objects with `type` and `label`
* @return {GrantType[]} List of objects with `type` and `label`
* properties.

@@ -87,3 +101,3 @@ */

* A handler for `focus` event on a label that contains text and
* should be coppied to clipboard when user is interacting with it.
* should be copied to clipboard when user is interacting with it.
*

@@ -97,22 +111,3 @@ * @param {KeyboardEvent} e

const errorTemplate = (msg) => {
return html`<p class="error-message">⚠ ${msg}</p>`;
};
/**
* @typedef {Object} Oauth2Params
* @property {string} grantType - OAuth 2 grant type
* @property {string} type - The same as `grantType`, used fpor compatibility.
* @property {string=} clientId - Registered client ID
* @property {string=} clientSecret - Registered client secret
* @property {string=} accessToken - Current access token
* @property {String[]=} scopes - List of token scopes. Can be undefined
* @property {string=} password - User password value
* @property {string=} username - User name value
* @property {string=} authorizationUri - User authorization URI
* @property {string=} accessTokenUri - Token exchange URI
* @property {string=} state - Generated state parameter for current request
*/
/**
* @param {AuthorizationMethod} base

@@ -123,9 +118,8 @@ */

/**
* @return {Boolean} Computed value, true if the grant type is a cutom definition.
* @return {boolean} Computed value, true if the response type is a custom definition.
*/
get isCustomGrant() {
get isCustomGrantType() {
const { grantType } = this;
return (
!!grantType &&
[
return (!!grantType &&
![
'implicit',

@@ -135,3 +129,3 @@ 'authorization_code',

'password',
].indexOf(grantType) === -1
].includes(grantType)
);

@@ -142,13 +136,10 @@ }

const { grantType } = this;
return ['client_credentials', 'password'].indexOf(grantType) === -1;
return !['client_credentials', 'password'].includes(grantType);
}
get oauth2ClientSecretRendered() {
const { grantType, isCustomGrant } = this;
const { grantType, isCustomGrantType } = this;
return (
isCustomGrant ||
(!!grantType &&
['authorization_code', 'client_credentials', 'password'].indexOf(
grantType
) !== -1)
isCustomGrantType ||
(!!grantType && ['authorization_code', 'client_credentials', 'password'].includes(grantType))
);

@@ -159,11 +150,11 @@ }

const { grantType } = this;
return ['authorization_code'].indexOf(grantType) !== -1;
return ['authorization_code'].includes(grantType);
}
get oauth2AuthorizationUriRendered() {
const { grantType, isCustomGrant } = this;
const { grantType, isCustomGrantType } = this;
return (
isCustomGrant ||
isCustomGrantType ||
(!!grantType &&
['implicit', 'authorization_code'].indexOf(grantType) !== -1)
['implicit', 'authorization_code'].includes(grantType))
);

@@ -173,9 +164,7 @@ }

get oauth2AccessTokenUriRendered() {
const { grantType, isCustomGrant } = this;
const { grantType, isCustomGrantType } = this;
return (
isCustomGrant ||
isCustomGrantType ||
(!!grantType &&
['client_credentials', 'authorization_code', 'password'].indexOf(
grantType
) !== -1)
['client_credentials', 'authorization_code', 'password'].includes(grantType))
);

@@ -185,5 +174,5 @@ }

get oauth2PasswordRendered() {
const { grantType, isCustomGrant } = this;
const { grantType, isCustomGrantType } = this;
return (
isCustomGrant || (!!grantType && ['password'].indexOf(grantType) !== -1)
isCustomGrantType || (!!grantType && ['password'].includes(grantType))
);

@@ -194,11 +183,14 @@ }

return {
// Seleted authorization grand type.
/**
* Selected authorization grand type.
*/
grantType: { type: String },
// The client ID for the auth token.
/**
* The client ID for the auth token.
*/
clientId: { type: String },
// The client secret. It to be used when selected server flow.
/**
* The client secret. It to be used when selected server flow.
*/
clientSecret: { type: String },
/**

@@ -215,3 +207,2 @@ * List of user selected scopes.

allowedScopes: { type: Array },
/**

@@ -222,19 +213,13 @@ * If true then the `oauth2-scope-selector` will disallow to add a scope that is not

preventCustomScopes: { type: Boolean },
/**
* When the user authorized the app it should be set to the token value.
* This element do not perform authorization. Other elements must intercept
* `oauth2-token-requested` and perform the authorization.
* the token request event and perform the authorization.
*/
accessToken: { type: String },
/**
* Received from the response token value.
* By default it is "bearer" as the only one defined in OAuth 2.0
* spec.
* If the token response contains `tokenType` property this value is
* updated.
* By default it is "bearer" as the only one defined in OAuth 2.0 spec.
* If the token response contains `tokenType` property then this value is updated.
*/
tokenType: { type: String },
/**

@@ -244,9 +229,7 @@ * Currently available grant types.

grantTypes: { type: Array },
/**
* If set it renders autorization url, token url and scopes as advanced options
* If set it renders authorization url, token url and scopes as advanced options
* which are then invisible by default. User can oen setting using the UI.
*/
isAdvanced: { type: Boolean },
advanced: { type: Boolean },
/**

@@ -256,84 +239,75 @@ * If true then the advanced options are opened.

advancedOpened: { type: Boolean },
/**
* If set, the grant type selector is hidden from the UI.
* If set, the response type selector is hidden from the UI.
*/
noGrantType: { type: Boolean },
/**
* Default delivery method of access token. Reported with
* settings change event as `deliveryMethod`.
*
* This value is added to event's `settings` property.
*
* When setting AMF model, this value may change, if AMF description
* forces different than default placement of the token.
* Informs about what filed of the authenticated request the token property should be set.
* By default the value is `header` which corresponds to the `authorization` by default,
* but it is configured by the `deliveryName` property.
*
* This can be used by the AMF model when the API spec defines where the access token should be
* put in the authenticated request.
*
* @default header
*/
oauthDeliveryMethod: { type: String },
/**
* Default parameter name that carries access token. Reported with
* the settings change event as `deliveryName`.
*
* This value is added to event's `settings` property.
*
* When setting AMF model, this value may change, if AMF description
* forces different than default parameter name for the token.
* The name of the authenticated request property that carries the token.
* By default it is `authorization` which corresponds to `header` value of the `deliveryMethod` property.
*
* By setting both `deliveryMethod` and `deliveryName` you instruct the application (assuming it reads this values)
* where to put the authorization token.
*
* @default authorization
*/
oauthDeliveryName: { type: String },
/**
* A base URI to use to construct correct URLs to authorization endpoints.
* The UI will present authorization endpoints as provided by the user
* or attributes. However, if the paths are relative (must start with '/')
* then base URI is added to the path.
* The base URI to use to construct the correct URLs to the authorization endpoints.
*
* When the paths are relative then base URI is added to the path.
* Relative paths must start with '/'.
*
* Note, URL processing is happening internally in the component. The produced authorize event
* will have base URI already applied.
*/
baseUri: { type: String },
/**
* An error message returned by the authorizartion.
* It renders error dialog when an error ocurred. It is automaticzally cleared
* when the user request the token again.
* The error message returned by the authorization library.
* It renders error dialog when an error ocurred.
* It is automatically cleared when the user request the token again.
*/
lastErrorMessage: { type: String },
/**
* When this property is set then the PKCE option is not rendered for the
* `authorization_code`. This is mainly meant to be used by the `api-authorization-method`
* to keep this control disabled and override generated settings when the API spec
* says that the PKCE is supported.
*/
noPkce: { type: Boolean },
/**
* Whether or not the PKCE extension is enabled for this authorization configuration.
* Note, PKCE, per the spec, is only available for `authorization_code` grantType.
*/
pkce: { type: Boolean },
};
}
/**
* @return {string|null} Last generated state or null of not generated.
*/
get lastState() {
return this._lastState || null;
}
constructor() {
super();
this[_oauth2ErrorHandler] = this[_oauth2ErrorHandler].bind(this);
this[_tokenSuccessHandler] = this[_tokenSuccessHandler].bind(this);
/**
* @type {GrantType[]}
*/
this.grantTypes = [];
this.noGrantType = false;
this.noPkce = false;
this.pkce = false;
}
_attachListeners(node) {
super._attachListeners(node);
node.addEventListener('oauth2-error', this[_oauth2ErrorHandler]);
node.addEventListener(
'oauth2-token-response',
this[_tokenSuccessHandler]
);
}
_detachListeners(node) {
super._detachListeners(node);
node.removeEventListener('oauth2-error', this[_oauth2ErrorHandler]);
node.removeEventListener(
'oauth2-token-response',
this[_tokenSuccessHandler]
);
}
/**
* Restores previously serialized values
* @param {Oauth2Params} settings
* @param {OAuth2Settings} settings
*/
[restoreOauth2Auth](settings) {
const type = settings.grantType || settings.type;
const type = settings.grantType;
this.grantType = type;

@@ -343,2 +317,5 @@ this.clientId = settings.clientId;

this.scopes = settings.scopes;
if (settings.tokenType) {
this.tokenType = settings.tokenType;
}
switch (type) {

@@ -352,2 +329,3 @@ case 'implicit':

this.accessTokenUri = settings.accessTokenUri;
this.pkce = settings.pkce;
break;

@@ -377,16 +355,15 @@ case 'client_credentials':

* Serializes OAuth2 parameters into a configuration object.
* @return {Oauth2Params}
* @return {OAuth2Settings}
*/
[serializeOauth2Auth]() {
const { grantType } = this;
const detail = {
type: grantType,
const { grantType, tokenType, } = this;
const detail = /** @type OAuth2Settings */ ({
grantType,
tokenType,
clientId: this.clientId,
accessToken: this.accessToken || '',
tokenType: this.tokenType,
scopes: this.scopes,
deliveryMethod: this.oauthDeliveryMethod,
deliveryName: this.oauthDeliveryName,
};
});

@@ -405,2 +382,3 @@ switch (grantType) {

detail.redirectUri = this[readUrlValue](this.redirectUri);
detail.pkce = this.pkce;
break;

@@ -420,3 +398,3 @@ case 'client_credentials':

default:
// Custom grant type.
// Custom response type.
detail.authorizationUri = this[readUrlValue](this.authorizationUri);

@@ -463,3 +441,3 @@ detail.clientSecret = this.clientSecret;

}
if (!this.grantTypes) {
if (!Array.isArray(this.grantTypes) || !this.grantTypes.length) {
this.grantTypes = oauth2GrantTypes;

@@ -477,8 +455,8 @@ }

[clearOauth2Auth]() {
this.tokenType = '';
this.accessToken = '';
this.grantType = '';
this.accessToken = '';
this.tokenType = '';
this.scopes = [];
this.oauthDeliveryMethod = '';
this.oauthDeliveryName = '';
this.scopes = /** @type string[] */ ([]);
this.oauthDeliveryMethod = undefined;
this.oauthDeliveryName = undefined;
this.authorizationUri = '';

@@ -494,3 +472,9 @@ this.accessTokenUri = '';

[authorizeOauth2]() {
/**
* Performs the authorization.
*
* @returns {Promise<TokenInfo|null>} The auth token or null if couldn't be requested.
* @throws {Error} When authorization error
*/
async [authorizeOauth2]() {
if (this.lastErrorMessage) {

@@ -501,66 +485,35 @@ this.lastErrorMessage = undefined;

if (!validationResult) {
return false;
return null;
}
this._authorizing = true;
const detail = this[serializeOauth2Auth]();
this._lastState = this.generateState();
detail.state = this._lastState;
const e = new CustomEvent('oauth2-token-requested', {
detail,
bubbles: true,
composed: true,
cancelable: true,
});
this.dispatchEvent(e);
if (!e.defaultPrevented) {
return false;
}
this._authorizing = true;
return true;
}
/**
* Handler for `oauth2-error` custom event.
* Informs the user about the error in the flow if the state property
* is the one used with the request.
*
* @param {CustomEvent} e
*/
[_oauth2ErrorHandler](e) {
const info = e.detail;
// API console may not support state check (may not return it back)
if (typeof info.state !== 'undefined') {
if (info.state !== this._lastState) {
return;
const state = this.generateState();
detail.state = state;
let tokenInfo = /** @type TokenInfo */(null);
try {
tokenInfo = await AuthorizationEvents.OAuth2.authorize(this, detail);
this._authorizing = false;
if (!tokenInfo) {
return null;
}
}
this._authorizing = false;
this._lastState = undefined;
const { message = 'Unknown error' } = e.detail;
this.lastErrorMessage = message;
}
/**
* Handler for the token response from the authorization component.
*
* @param {CustomEvent} e
*/
[_tokenSuccessHandler](e) {
const info = e.detail;
// API console may not support state check (may not return it back)
if (typeof info.state !== 'undefined') {
if (info.state !== this._lastState) {
return;
if (tokenInfo.state !== state) {
return null;
}
}
this._authorizing = false;
this._lastState = undefined;
if (info.accessToken && info.accessToken !== this.accessToken) {
if (info.tokenType && info.tokenType !== this.tokenType) {
this.tokenType = info.tokenType;
} else if (!info.tokenType && this.tokenType !== 'Bearer') {
this.tokenType = 'Bearer';
if (tokenInfo.accessToken && tokenInfo.accessToken !== this.accessToken) {
if (tokenInfo.tokenType && tokenInfo.tokenType !== this.tokenType) {
this.tokenType = tokenInfo.tokenType;
} else if (!tokenInfo.tokenType && this.tokenType !== 'Bearer') {
this.tokenType = 'Bearer';
}
this.accessToken = tokenInfo.accessToken;
notifyChange(this);
}
this.accessToken = info.accessToken;
notifyChange(this);
} catch (e) {
const { message = 'Unknown error' } = e;
this.lastErrorMessage = message;
this._authorizing = false;
await this.requestUpdate();
throw e;
}
return tokenInfo;
}

@@ -613,3 +566,3 @@

if (!advOpened) {
this.isAdvanced = true;
this.advanced = true;
}

@@ -620,7 +573,7 @@ }

* A handler for `focus` event on a label that contains text and
* should be coppied to clipboard when user is interacting with it.
* should be copied to clipboard when user is interacting with it.
*
* @param {MouseEvent} e
*/
[_clickCopyAction](e) {
[clickCopyAction](e) {
const node = /** @type {HTMLElement} */ (e.target);

@@ -633,39 +586,57 @@ const elm = this.shadowRoot.querySelector('clipboard-copy');

}
setTimeout(() => {
makeNodeSelection(node);
});
setTimeout(() => makeNodeSelection(node));
}
[_scopesChanged](e) {
this.scopes = e.detail.value;
/**
* Event handler for the scopes element changed state
* @param {CustomEvent} e
*/
[scopesChanged](e) {
this.scopes = /** @type OAuth2ScopeSelector */ (e.target).value;
notifyChange(this);
}
[_advHandler](e) {
[advHandler](e) {
this.advancedOpened = e.target.checked;
}
[_oauth2RedirectTemplate]() {
/**
* The handler for the change event coming from the PKCE input checkbox
* @param {Event} e
*/
[pkceChangeHandler](e) {
const node = /** @type AnypointCheckbox */ (e.target);
this.pkce = node.checked;
}
/**
* @returns {TemplateResult|string} The template for the OAuth 2 redirect URI label
*/
[oauth2RedirectTemplate]() {
const { redirectUri } = this;
return html`<div class="subtitle">Redirect URI</div>
<section>
<div class="redirect-section">
<p class="redirect-info">
Set this redirect URI in OAuth 2.0 provider settings.
</p>
<p class="read-only-param-field padding">
<span
class="code"
@click="${this[_clickCopyAction]}"
@focus="${selectFocusable}"
title="Click to copy the URI"
tabindex="0"
>${redirectUri}</span
>
</p>
</div>
</section>`;
return html`
<div class="subtitle">Redirect URI</div>
<section>
<div class="redirect-section">
<p class="redirect-info">
Set this redirect URI in OAuth 2.0 provider settings.
</p>
<p class="read-only-param-field padding">
<span
class="code"
@click="${this[clickCopyAction]}"
@focus="${selectFocusable}"
title="Click to copy the URI"
tabindex="0"
>${redirectUri}</span>
</p>
</div>
</section>
`;
}
[_oauth2GrantTypeTemplate]() {
/**
* @returns {TemplateResult|string} The template for the OAuth 2 response type selector
*/
[oauth2GrantTypeTemplate]() {
const {

@@ -678,8 +649,9 @@ grantType,

noGrantType,
isCustomGrant,
isCustomGrantType,
} = this;
const items = this.grantTypes || [];
return html` <anypoint-dropdown-menu
return html`
<anypoint-dropdown-menu
name="grantType"
?required="${!isCustomGrant}"
?required="${!isCustomGrantType}"
class="grant-dropdown"

@@ -689,6 +661,5 @@ ?hidden="${noGrantType}"

.compatibility="${compatibility}"
.readOnly="${readOnly}"
.disabled="${disabled}"
.disabled="${disabled||readOnly}"
>
<label slot="label">Grant type</label>
<label slot="label">Response type</label>
<anypoint-listbox

@@ -699,16 +670,11 @@ slot="dropdown-content"

data-name="grantType"
.outlined="${outlined}"
.compatibility="${compatibility}"
.readOnly="${readOnly}"
.disabled="${disabled}"
.disabled="${disabled||readOnly}"
attrforselected="data-value"
>
${items.map(
(item) =>
html`<anypoint-item
.compatibility="${compatibility}"
data-value="${item.type}"
>${item.label}</anypoint-item
>`
)}
${items.map((item) => html`
<anypoint-item
.compatibility="${compatibility}"
data-value="${item.type}"
>${item.label}</anypoint-item>`)}
</anypoint-listbox>

@@ -718,20 +684,8 @@ </anypoint-dropdown-menu>`;

[_oauth2AdvancedTemplate]() {
/**
* @returns {TemplateResult|string} The template for the OAuth 2 advanced options.
*/
[oauth2AdvancedTemplate]() {
const {
isCustomGrant,
advancedOpened,
oauth2AuthorizationUriRendered,
authorizationUri,
oauth2AccessTokenUriRendered,
accessTokenUri,
oauth2PasswordRendered,
username,
password,
allowedScopes,
preventCustomScopes,
outlined,
compatibility,
readOnly,
disabled,
scopes,
baseUri,

@@ -743,92 +697,20 @@ } = this;

const urlType = baseUri ? 'string' : 'url';
return html`<div class="advanced-section" ?hidden="${!advancedOpened}">
${oauth2AuthorizationUriRendered
? inputTemplate(
'authorizationUri',
authorizationUri,
'Authorization URI',
this[inputHandler],
{
outlined,
compatibility,
readOnly,
disabled,
type: urlType,
required: !isCustomGrant,
autoValidate: true,
invalidLabel:
'Authorization URI is required for this grant type',
}
)
: ''}
${oauth2AccessTokenUriRendered
? inputTemplate(
'accessTokenUri',
accessTokenUri,
'Access token URI',
this[inputHandler],
{
outlined,
compatibility,
readOnly,
disabled,
type: urlType,
required: !isCustomGrant,
autoValidate: true,
invalidLabel:
'Access token URI is required for this grant type',
}
)
: ''}
${oauth2PasswordRendered
? inputTemplate(
'username',
username,
'Username',
this[inputHandler],
{
outlined,
compatibility,
readOnly,
disabled,
required: !isCustomGrant,
autoValidate: true,
invalidLabel: 'User name is required for this grant type',
}
)
: ''}
${oauth2PasswordRendered
? inputTemplate(
'password',
password,
'Password',
this[inputHandler],
{
outlined,
compatibility,
readOnly,
disabled,
required: !isCustomGrant,
autoValidate: true,
invalidLabel: 'Password is required for this grant type',
}
)
: ''}
<oauth2-scope-selector
.allowedScopes="${allowedScopes}"
.preventCustomScopes="${preventCustomScopes}"
.value="${scopes}"
.readOnly="${readOnly}"
.disabled="${disabled}"
.outlined="${outlined}"
.compatibility="${compatibility}"
name="scopes"
@value-changed="${this[_scopesChanged]}"
></oauth2-scope-selector>
return html`
<div class="advanced-section" ?hidden="${!advancedOpened}">
${this[authorizationUriTemplate](urlType)}
${this[accessTokenUriTemplate](urlType)}
${this[usernameTemplate]()}
${this[passwordTemplateLocal]()}
${this[scopesTemplate]()}
${this[pkceTemplate]()}
</div>`;
}
[_oath2AuthorizeTemplate]() {
/**
* @returns {TemplateResult|string} The template for the "authorize" button.
*/
[oath2AuthorizeTemplate]() {
const { _authorizing, compatibility } = this;
return html`<div class="authorize-actions">
return html`
<div class="authorize-actions">
<anypoint-button

@@ -841,15 +723,16 @@ ?disabled="${_authorizing}"

@click="${this.authorize}"
>Request access token</anypoint-button
>
>Request access token</anypoint-button>
</div>`;
}
[_oauth2TokenTemplate]() {
/**
* @returns {TemplateResult|string} The template for the OAuth 2 token value
*/
[oauth2TokenTemplate]() {
const { accessToken, compatibility, _authorizing } = this;
return html`<div class="current-token">
return html`
<div class="current-token">
<label class="token-label">Current token</label>
<p class="read-only-param-field padding">
<span class="code" @click="${this[_clickCopyAction]}"
>${accessToken}</span
>
<span class="code" @click="${this[clickCopyAction]}">${accessToken}</span>
</p>

@@ -863,6 +746,4 @@ <div class="authorize-actions">

data-type="refresh-token"
@click="${this.authorize}
"
>Refresh access token</anypoint-button
>
@click="${this.authorize}"
>Refresh access token</anypoint-button>
</div>

@@ -872,13 +753,213 @@ </div>`;

/**
* @returns {TemplateResult} The template for the OAuth 2 editor.
*/
[renderOauth2Auth]() {
const {
clientId,
oauth2ClientSecretRendered,
clientSecret,
isAdvanced,
advancedOpened,
accessToken,
clientIdRequired,
oauth2ClientSecretRequired,
lastErrorMessage,
} = this;
return html`
<form autocomplete="on" class="oauth2-auth">
${this[oauth2GrantTypeTemplate]()}
${this[clientIdTemplate]()}
${this[clientSecretTemplate]()}
${this[oauth2CustomPropertiesTemplate]()}
${this[toggleAdvViewSwitchTemplate]()}
${this[oauth2AdvancedTemplate]()}
</form>
${this[oauth2RedirectTemplate]()}
${accessToken ? this[oauth2TokenTemplate]() : this[oath2AuthorizeTemplate]()}
${lastErrorMessage ? html`<p class="error-message">⚠ ${lastErrorMessage}</p>` : ''}
<clipboard-copy></clipboard-copy>
`;
}
[oauth2CustomPropertiesTemplate]() {
return '';
}
/**
* @returns {TemplateResult|string} The template for the OAuth 2 client secret input.
*/
[clientSecretTemplate]() {
const { oauth2ClientSecretRendered } = this;
if (!oauth2ClientSecretRendered) {
return '';
}
const { clientSecret, outlined, compatibility, readOnly, disabled, oauth2ClientSecretRequired } = this;
return passwordTemplate(
'clientSecret',
clientSecret,
'Client secret',
this[inputHandler],
{
outlined,
compatibility,
readOnly,
disabled,
required: oauth2ClientSecretRequired,
autoValidate: true,
invalidLabel: 'Client secret is required for this response type',
}
);
}
/**
* @returns {TemplateResult|string} The template for the OAuth 2 client id input.
*/
[clientIdTemplate]() {
const { clientId, outlined, compatibility, readOnly, disabled, clientIdRequired } = this;
return passwordTemplate(
'clientId',
clientId,
'Client id',
this[inputHandler],
{
outlined,
compatibility,
readOnly,
disabled,
required: clientIdRequired,
autoValidate: true,
invalidLabel: 'Client ID is required for this response type',
infoLabel: clientIdRequired
? undefined
: 'Client id is optional for this response type',
}
);
}
/**
* @returns {TemplateResult|string} The template for the toggle advanced view switch
*/
[toggleAdvViewSwitchTemplate]() {
const { advanced } = this;
if (!advanced) {
return '';
}
const { readOnly, advancedOpened, compatibility } = this;
return html`
<div class="adv-toggle">
<anypoint-switch
class="adv-settings-input"
.checked="${advancedOpened}"
@change="${this[advHandler]}"
?disabled="${readOnly}"
?compatibility="${compatibility}"
>Advanced settings</anypoint-switch>
</div>`;
}
/**
* @param {string} urlType The input type to render
* @returns {TemplateResult|string} The template for the authorization URI input
*/
[authorizationUriTemplate](urlType) {
if (!this.oauth2AuthorizationUriRendered) {
return '';
}
const { readOnly, authorizationUri, compatibility, outlined, disabled, isCustomGrantType } = this;
return inputTemplate(
'authorizationUri',
authorizationUri,
'Authorization URI',
this[inputHandler],
{
outlined,
compatibility,
readOnly,
disabled,
type: urlType,
required: !isCustomGrantType,
autoValidate: true,
invalidLabel: 'Authorization URI is required for this response type',
}
);
}
/**
* @param {string} urlType The input type to render
* @returns {TemplateResult|string} The template for the access token URI input
*/
[accessTokenUriTemplate](urlType) {
if (!this.oauth2AccessTokenUriRendered) {
return '';
}
const { readOnly, accessTokenUri, compatibility, outlined, disabled, isCustomGrantType } = this;
return inputTemplate(
'accessTokenUri',
accessTokenUri,
'Access token URI',
this[inputHandler],
{
outlined,
compatibility,
readOnly,
disabled,
type: urlType,
required: !isCustomGrantType,
autoValidate: true,
invalidLabel: 'Access token URI is required for this response type',
}
);
}
/**
* @returns {TemplateResult|string} The template for the user name input
*/
[usernameTemplate]() {
if (!this.oauth2PasswordRendered) {
return '';
}
const { readOnly, username, compatibility, outlined, disabled, isCustomGrantType } = this;
return inputTemplate(
'username',
username,
'Username',
this[inputHandler],
{
outlined,
compatibility,
readOnly,
disabled,
required: !isCustomGrantType,
autoValidate: true,
invalidLabel: 'User name is required for this response type',
}
);
}
/**
* @returns {TemplateResult|string} The template for the user password input
*/
[passwordTemplateLocal]() {
if (!this.oauth2PasswordRendered) {
return '';
}
const { readOnly, password, compatibility, outlined, disabled, isCustomGrantType } = this;
return inputTemplate(
'password',
password,
'Password',
this[inputHandler],
{
outlined,
compatibility,
readOnly,
disabled,
required: !isCustomGrantType,
autoValidate: true,
invalidLabel: 'Password is required for this response type',
}
);
}
/**
* @returns {TemplateResult} The template for the OAuth 2 scopes input
*/
[scopesTemplate]() {
const {
allowedScopes,
preventCustomScopes,
outlined,

@@ -888,64 +969,35 @@ compatibility,

disabled,
scopes,
} = this;
return html`<form autocomplete="on" class="oauth2-auth">
${this[_oauth2GrantTypeTemplate]()}
${passwordTemplate(
'clientId',
clientId,
'Client id',
this[inputHandler],
{
outlined,
compatibility,
readOnly,
disabled,
required: clientIdRequired,
autoValidate: true,
invalidLabel: 'Client ID is required for this grant type',
infoLabel: clientIdRequired
? undefined
: 'Client id is optional for this grant type',
}
)}
${oauth2ClientSecretRendered
? passwordTemplate(
'clientSecret',
clientSecret,
'Client secret',
this[inputHandler],
{
outlined,
compatibility,
readOnly,
disabled,
required: oauth2ClientSecretRequired,
autoValidate: true,
invalidLabel: 'Client secret is required for this grant type',
}
)
: ''}
${this[oauth2CustomPropertiesTemplate]()}
${isAdvanced
? html` <div class="adv-toggle">
<anypoint-switch
class="adv-settings-input"
.checked="${advancedOpened}"
@change="${this[_advHandler]}"
?disabled="${readOnly}"
?compatibility="${compatibility}"
>Advanced settings</anypoint-switch
>
</div>`
: ''}
${this[_oauth2AdvancedTemplate]()}
</form>
${this[_oauth2RedirectTemplate]()}
${accessToken
? this[_oauth2TokenTemplate]()
: this[_oath2AuthorizeTemplate]()}
${lastErrorMessage ? errorTemplate(lastErrorMessage) : ''}
<clipboard-copy></clipboard-copy>`;
return html`
<oauth2-scope-selector
.allowedScopes="${allowedScopes}"
.preventCustomScopes="${preventCustomScopes}"
.value="${scopes}"
?readOnly="${readOnly}"
?disabled="${disabled}"
?outlined="${outlined}"
?compatibility="${compatibility}"
name="scopes"
@change="${this[scopesChanged]}"
></oauth2-scope-selector>`;
}
[oauth2CustomPropertiesTemplate]() {}
/**
* @returns {TemplateResult|string} The template for the PKCE option of the OAuth 2 extension.
*/
[pkceTemplate]() {
const { grantType, noPkce, pkce } = this;
if (noPkce || grantType !== 'authorization_code') {
return '';
}
return html`
<anypoint-checkbox
.checked="${pkce}"
title="Enables PKCE extension of the OAuth 2 protocol."
name="pkce"
@change="${this[pkceChangeHandler]}"
>Use PKCE extension</anypoint-checkbox>
`;
}
}

@@ -952,0 +1004,0 @@ return Oauth2MethodMixinImpl;

@@ -131,4 +131,3 @@ import {

* Note, this uses form-associated custom elements API. At this moment (Nov 2019)
* it is only available in CHrome 77. FF is implementing it and Edge will be
* Chome soon.
* it is only available in CHrome 77. FF is implementing it and Edge will be soon.
*

@@ -135,0 +134,0 @@ * @param {HTMLFormElement} form The form to validate

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc