{"action":"reopened","issue":{"url":"https://api.github.com/repos/Moya/Moya/issues/1283","repository_url":"https://api.github.com/repos/Moya/Moya","labels_url":"https://api.github.com/repos/Moya/Moya/issues/1283/labels{/name}","comments_url":"https://api.github.com/repos/Moya/Moya/issues/1283/comments","events_url":"https://api.github.com/repos/Moya/Moya/issues/1283/events","html_url":"https://github.com/Moya/Moya/issues/1283","id":257494088,"number":1283,"title":"Allowing parameters and headers to be reused across providers","user":{"login":"SD10","id":7445580,"avatar_url":"https://avatars0.githubusercontent.com/u/7445580?v=4","gravatar_id":"","url":"https://api.github.com/users/SD10","html_url":"https://github.com/SD10","followers_url":"https://api.github.com/users/SD10/followers","following_url":"https://api.github.com/users/SD10/following{/other_user}","gists_url":"https://api.github.com/users/SD10/gists{/gist_id}","starred_url":"https://api.github.com/users/SD10/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SD10/subscriptions","organizations_url":"https://api.github.com/users/SD10/orgs","repos_url":"https://api.github.com/users/SD10/repos","events_url":"https://api.github.com/users/SD10/events{/privacy}","received_events_url":"https://api.github.com/users/SD10/received_events","type":"User","site_admin":false},"labels":[{"id":692792255,"url":"https://api.github.com/repos/Moya/Moya/labels/discussion","name":"discussion","color":"b60205","default":false},{"id":618895614,"url":"https://api.github.com/repos/Moya/Moya/labels/stale","name":"stale","color":"bfdadc","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2017-09-13T19:27:59Z","updated_at":"2017-10-21T23:14:22Z","closed_at":null,"author_association":"MEMBER","body":"### Background\r\nThis is inspired by issue #1273 and its matching pull request #1279.\r\n\r\nBasically, #1273 discusses extending the behavior of Moya's current `AccessTokenPlugin` to support adding an `access_token` as a URL parameter to a request. \r\n\r\nWhile this parameter *can* be added directly to the parameters of a `TargetType`, the fact that it needs to be applied to every request makes it a good candidate for improving the existing `AccessTokenPlugin`.\r\n\r\n### AccessTokenPlugin Current Behavior\r\nCurrently, the `AccessTokenPlugin` only supports authentication using an `\"Authorization\"` header with the values of `\"Basic\"` or `\"Bearer\"`. Supporting auth via parameters would be a new concept for this plugin.\r\n\r\n### Proposed Solutions\r\n\r\n1.) Adding another case to the `AuthorizationType` enum:\r\n```Swift\r\npublic enum AuthorizationType: String {\r\n    case basic = \"Basic\"\r\n    case bearer = \"Bearer\"\r\n    case urlParamter = \"access_token\"\r\n    case none\r\n}\r\n```\r\nThis raises the question: What if the API has different parameter names? Ex) `api_key` or `api_token`\r\n\r\n2.) Using associated values over raw values:\r\n```Swift\r\npublic enum AuthorizationType {\r\n    case header(name: String)\r\n    case urlParameter(name: String)\r\n    case none\r\n}\r\n```\r\n\r\n3. Specifying the parameter name or header name in the `AccessTokenPlugin` initializer:\r\n```Swift\r\ninit(tokenClosure: ..., parameterName: ..., headerName: ...) { ... }\r\n\r\nenum AuthorizationType {\r\n    case basicInHeaders\r\n    case bearerInHeaders\r\n    case basicInParameters\r\n    case bearerInParameters\r\n    case none\r\n}\r\n```\r\n\r\n4. Splitting option 3 into two enums and requesting optional `AuthorizationType` in the target, where nil will mean no authorization will be appended:\r\n```swift\r\nenum AuthorizationType {\r\n    case basic\r\n    case bearer\r\n}\r\n\r\nenum AuthorizationTypePlacement {\r\n    case header\r\n    case parameter\r\n}\r\n```\r\n\r\n5. Providing a `HeaderPlugin` and `ParameterPlugin`:\r\n```Swift\r\nprotocol HeaderApplicable {\r\n    var applyPluginHeaders: Bool\r\n}\r\npublic struct HeaderPlugin: PluginType {\r\n    var headerValue: String\r\n    var headerName: String\r\n}\r\nprotocol ParameterApplicable {\r\n    var applyPluginParameters: Bool\r\n}\r\npublic struct ParameterPlugin: PluginType {\r\n   var parameterValue: Any\r\n   var parameterName: String\r\n   var encoding: ParameterEncoding\r\n}\r\n```\r\nApproach 5 moves away from the domain of `Authentication` and looks at the problem as being we need to reuse a specific parameter or specific header on requests across multiple providers or targets.\r\n\r\nSorry for the essay 😅 \r\n"}}
{"actor":{"display_login":"SD10"}}