{"action":"created","issue":{"url":"https://api.github.com/repos/scribejava/scribejava/issues/841","repository_url":"https://api.github.com/repos/scribejava/scribejava","labels_url":"https://api.github.com/repos/scribejava/scribejava/issues/841/labels{/name}","comments_url":"https://api.github.com/repos/scribejava/scribejava/issues/841/comments","events_url":"https://api.github.com/repos/scribejava/scribejava/issues/841/events","html_url":"https://github.com/scribejava/scribejava/issues/841","id":305596036,"number":841,"title":"Problem with Magento API and Ports","user":{"login":"tig-jeffreypeeters","id":32734718,"avatar_url":"https://avatars1.githubusercontent.com/u/32734718?v=4","gravatar_id":"","url":"https://api.github.com/users/tig-jeffreypeeters","html_url":"https://github.com/tig-jeffreypeeters","followers_url":"https://api.github.com/users/tig-jeffreypeeters/followers","following_url":"https://api.github.com/users/tig-jeffreypeeters/following{/other_user}","gists_url":"https://api.github.com/users/tig-jeffreypeeters/gists{/gist_id}","starred_url":"https://api.github.com/users/tig-jeffreypeeters/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tig-jeffreypeeters/subscriptions","organizations_url":"https://api.github.com/users/tig-jeffreypeeters/orgs","repos_url":"https://api.github.com/users/tig-jeffreypeeters/repos","events_url":"https://api.github.com/users/tig-jeffreypeeters/events{/privacy}","received_events_url":"https://api.github.com/users/tig-jeffreypeeters/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-03-15T15:16:47Z","updated_at":"2018-03-26T09:22:07Z","closed_at":null,"author_association":"NONE","body":"I'm using scribe to connect to my Magento backend but I run into a problem when I try to use the same setup on a site with a port in the url. For instance https://example.com:3333/. \r\n\r\nI found a ticket discussing this issue https://magento.stackexchange.com/questions/31806/oauth-401-oauth-problem-signature-invalid. \r\n\r\nNow my question is the following: Is it possible for me to create the signature using the url https://example.com/ while the call is made to https://example.com:3333/ ? \r\n\r\nThanks in advance for any help you can provide!"},"comment":{"url":"https://api.github.com/repos/scribejava/scribejava/issues/comments/376101724","html_url":"https://github.com/scribejava/scribejava/issues/841#issuecomment-376101724","issue_url":"https://api.github.com/repos/scribejava/scribejava/issues/841","id":376101724,"user":{"login":"kullfar","id":736714,"avatar_url":"https://avatars3.githubusercontent.com/u/736714?v=4","gravatar_id":"","url":"https://api.github.com/users/kullfar","html_url":"https://github.com/kullfar","followers_url":"https://api.github.com/users/kullfar/followers","following_url":"https://api.github.com/users/kullfar/following{/other_user}","gists_url":"https://api.github.com/users/kullfar/gists{/gist_id}","starred_url":"https://api.github.com/users/kullfar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kullfar/subscriptions","organizations_url":"https://api.github.com/users/kullfar/orgs","repos_url":"https://api.github.com/users/kullfar/repos","events_url":"https://api.github.com/users/kullfar/events{/privacy}","received_events_url":"https://api.github.com/users/kullfar/received_events","type":"User","site_admin":false},"created_at":"2018-03-26T09:22:07Z","updated_at":"2018-03-26T09:22:07Z","author_association":"OWNER","body":"Aha. Ok, I see.\r\nSigning process is here\r\nhttps://github.com/scribejava/scribejava/blob/master/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java#L169\r\n\r\ndocs: https://tools.ietf.org/html/rfc5849#section-3.4\r\n\r\nYou are using HMAC-SHA1\r\nhttps://tools.ietf.org/html/rfc5849#section-3.4.2\r\n\r\nBut it doesn't matter.\r\n\r\nthe interesting thing is the text to use as base for signing.\r\nhttps://tools.ietf.org/html/rfc5849#section-3.4.1.1\r\n\r\nhere it's calculated\r\n```final String baseString = api.getBaseStringExtractor().extract(request);```\r\n\r\naccording to the docs https://tools.ietf.org/html/rfc5849#section-3.4.1.2\r\n```\r\nThe port MUST be included if it is not the default port for the\r\n       scheme, and MUST be excluded if it is the default.  Specifically,\r\n       the port MUST be excluded when making an HTTP request [RFC2616]\r\n       to port 80 or when making an HTTPS request [RFC2818] to port 443.\r\n       All other non-default port numbers MUST be included.\r\n```\r\n\r\nThe default implementation in ScribeJava does exactly that:\r\n```\r\n    protected String getUrl(OAuthRequest request) {\r\n        return request.getSanitizedUrl();\r\n    }\r\n```\r\nhttps://github.com/scribejava/scribejava/blob/master/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java#L33\r\n\r\n```\r\n    /**\r\n     * Returns the URL without the port and the query string part.\r\n     *\r\n     * @return the OAuth-sanitized URL\r\n     */\r\n    public String getSanitizedUrl() {\r\n        if (url.startsWith(\"http://\") && (url.endsWith(\":80\") || url.contains(\":80/\"))) {\r\n            return url.replaceAll(\"\\\\?.*\", \"\").replaceAll(\":80\", \"\");\r\n        } else if (url.startsWith(\"https://\") && (url.endsWith(\":443\") || url.contains(\":443/\"))) {\r\n            return url.replaceAll(\"\\\\?.*\", \"\").replaceAll(\":443\", \"\");\r\n        } else {\r\n            return url.replaceAll(\"\\\\?.*\", \"\");\r\n        }\r\n    }\r\n```\r\nfrom https://github.com/scribejava/scribejava/blob/master/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java#L205\r\n\r\nSo, You are need the custom logic for base String creation.\r\nOverride getBaseStringExtractor method in your MagentoApi\r\nand return something like this new class\r\n```\r\nMagentoBaseStringExtractor extends BaseStringExtractorImpl {\r\n\r\n  @Override\r\n    protected String getUrl(OAuthRequest request) {\r\n        return <write here you code, with stripping the port instead of 'request.getSanitizedUrl()'>;\r\n    }\r\n```\r\nor smth like this.\r\n\r\nOr even\r\n```\r\nMagentoBaseStringExtractor extends BaseStringExtractorImpl {\r\n  private final String portToDelete;\r\n  MagentoBaseStringExtractor(int portToDelete) {\r\n    this.portToDelete = \":\"+portToDelete;\r\n  }\r\n\r\n  @Override\r\n    protected String getUrl(OAuthRequest request) {\r\n        return super.getUrl(request).replaceAll(portToDelete, \"\");\r\n    }\r\n\r\n----------\r\nMagentoAPI {\r\n  private final static int PORT = 3333;\r\n  private final static String URL  = \"https://....:\"+PORT;\r\n  private final static BaseStringExtractor BSE = new MagentoBaseStringExtractor(PORT);\r\n\r\n  @Override\r\n  BaseStringExtractor getBaseStringExtractor() {\r\n    return BSE;\r\n  }\r\n}\r\n```\r\n"}}
{"actor":{"display_login":"kullfar"}}