{"id":28577509,"url":"https://github.com/mastercard/oauth1-signer-java","last_synced_at":"2025-06-11T00:38:51.980Z","repository":{"id":50116623,"uuid":"127151303","full_name":"Mastercard/oauth1-signer-java","owner":"Mastercard","description":"Zero dependency library for generating a Mastercard API compliant OAuth signature.","archived":false,"fork":false,"pushed_at":"2024-05-26T21:13:24.000Z","size":247,"stargazers_count":49,"open_issues_count":0,"forks_count":30,"subscribers_count":18,"default_branch":"main","last_synced_at":"2024-11-15T21:59:43.285Z","etag":null,"topics":["java","mastercard","oauth1","oauth1a","openapi"],"latest_commit_sha":null,"homepage":"https://developer.mastercard.com/platform/documentation/security-and-authentication/using-oauth-1a-to-access-mastercard-apis/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mastercard.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-03-28T14:18:24.000Z","updated_at":"2024-11-04T15:35:34.000Z","dependencies_parsed_at":"2024-01-19T13:27:57.679Z","dependency_job_id":"9095c378-39c4-4e20-bfbc-1ebfb3f77783","html_url":"https://github.com/Mastercard/oauth1-signer-java","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mastercard%2Foauth1-signer-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mastercard%2Foauth1-signer-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mastercard%2Foauth1-signer-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mastercard%2Foauth1-signer-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mastercard","download_url":"https://codeload.github.com/Mastercard/oauth1-signer-java/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mastercard%2Foauth1-signer-java/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259177332,"owners_count":22817349,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","mastercard","oauth1","oauth1a","openapi"],"created_at":"2025-06-11T00:37:59.575Z","updated_at":"2025-06-11T00:38:51.961Z","avatar_url":"https://github.com/Mastercard.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# oauth1-signer-java\n[![](https://developer.mastercard.com/_/_/src/global/assets/svg/mcdev-logo-dark.svg)](https://developer.mastercard.com/)\n\n[![](https://github.com/Mastercard/oauth1-signer-java/workflows/Build%20\u0026%20Test/badge.svg)](https://github.com/Mastercard/oauth1-signer-java/actions?query=workflow%3A%22Build+%26+Test%22)\n[![](https://sonarcloud.io/api/project_badges/measure?project=Mastercard_oauth1-signer-java\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=Mastercard_oauth1-signer-java)\n[![](https://github.com/Mastercard/oauth1-signer-java/workflows/broken%20links%3F/badge.svg)](https://github.com/Mastercard/oauth1-signer-java/actions?query=workflow%3A%22broken+links%3F%22)\n[![](https://img.shields.io/maven-central/v/com.mastercard.developer/oauth1-signer.svg)](https://search.maven.org/artifact/com.mastercard.developer/oauth1-signer/)\n[![](https://www.javadoc.io/badge/com.mastercard.developer/oauth1-signer.svg?color=blue)](https://www.javadoc.io/doc/com.mastercard.developer/oauth1-signer)\n[![](https://img.shields.io/badge/license-MIT-yellow.svg)](https://github.com/Mastercard/oauth1-signer-java/blob/master/LICENSE)\n\n## Table of Contents\n- [Overview](#overview)\n  * [Compatibility](#compatibility)\n  * [References](#references)\n  * [Versioning and Deprecation Policy](#versioning)\n- [Usage](#usage)\n  * [Prerequisites](#prerequisites)\n  * [Adding the Library to Your Project](#adding-the-library-to-your-project)\n  * [Loading the Signing Key](#loading-the-signing-key) \n  * [Creating the OAuth Authorization Header](#creating-the-oauth-authorization-header)\n  * [Signing HTTP Client Request Objects](#signing-http-client-request-objects)\n  * [Integrating with OpenAPI Generator API Client Libraries](#integrating-with-openapi-generator-api-client-libraries)\n\n## Overview \u003ca name=\"overview\"\u003e\u003c/a\u003e\nZero dependency library for generating a Mastercard API compliant OAuth signature.\n\n### Compatibility \u003ca name=\"compatibility\"\u003e\u003c/a\u003e\nJava 11+\n\n### References \u003ca name=\"references\"\u003e\u003c/a\u003e\n* [OAuth 1.0a specification](https://tools.ietf.org/html/rfc5849)\n* [Body hash extension for non application/x-www-form-urlencoded payloads](https://tools.ietf.org/id/draft-eaton-oauth-bodyhash-00.html)\n\n### Versioning and Deprecation Policy \u003ca name=\"versioning\"\u003e\u003c/a\u003e\n* [Mastercard Versioning and Deprecation Policy](https://github.com/Mastercard/.github/blob/main/CLIENT_LIBRARY_DEPRECATION_POLICY.md)\n\n## Usage \u003ca name=\"usage\"\u003e\u003c/a\u003e\n### Prerequisites \u003ca name=\"prerequisites\"\u003e\u003c/a\u003e\nBefore using this library, you will need to set up a project in the [Mastercard Developers Portal](https://developer.mastercard.com). \n\nAs part of this set up, you'll receive credentials for your app:\n* A consumer key (displayed on the Mastercard Developer Portal)\n* A private request signing key (matching the public certificate displayed on the Mastercard Developer Portal)\n\n### Adding the Library to Your Project \u003ca name=\"adding-the-library-to-your-project\"\u003e\u003c/a\u003e\n\n#### Maven\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.mastercard.developer\u003c/groupId\u003e\n    \u003cartifactId\u003eoauth1-signer\u003c/artifactId\u003e\n    \u003cversion\u003e${oauth1-signer-version}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n#### Gradle\n```\ndependencies {\n    implementation \"com.mastercard.developer:oauth1-signer:$oauth1SignerVersion\"\n}\n```\n\n#### Other Dependency Managers\nSee: https://search.maven.org/artifact/com.mastercard.developer/oauth1-signer\n\n### Loading the Signing Key \u003ca name=\"loading-the-signing-key\"\u003e\u003c/a\u003e\n\nA `PrivateKey` key object can be created by calling the `AuthenticationUtils.loadSigningKey` method:\n```java\nPrivateKey signingKey = AuthenticationUtils.loadSigningKey(\n                                    \"\u003cinsert PKCS#12 key file path\u003e\", \n                                    \"\u003cinsert key alias\u003e\", \n                                    \"\u003cinsert key password\u003e\");\n```\n\n### Creating the OAuth Authorization Header \u003ca name=\"creating-the-oauth-authorization-header\"\u003e\u003c/a\u003e\nThe method that does all the heavy lifting is `OAuth.getAuthorizationHeader`. You can call into it directly and as long as you provide the correct parameters, it will return a string that you can add into your request's `Authorization` header.\n\n```java\nString consumerKey = \"\u003cinsert consumer key\u003e\";\nURI uri = URI.create(\"https://sandbox.api.mastercard.com/service\");\nString method = \"POST\";\nString payload = \"Hello world!\";\nCharset charset = StandardCharsets.UTF_8;\nString authHeader = OAuth.getAuthorizationHeader(uri, method, payload, charset, consumerKey, signingKey);\n```\n\n### Signing HTTP Client Request Objects \u003ca name=\"signing-http-client-request-objects\"\u003e\u003c/a\u003e\n\nAlternatively, you can use helper classes for some of the commonly used HTTP clients.\n\nThese classes, provided in the `com.mastercard.developer.signers` package, will modify the provided request object in-place and will add the correct `Authorization` header. Once instantiated with a consumer key and private key, these objects can be reused. \n\nUsage briefly described below, but you can also refer to the test package for examples. \n\n+ [Java HttpsURLConnection](#java-httpsurlconnection)\n+ [Apache HTTP Client 4](#apache-http-client-4)\n+ [OkHttp 3](#okhttp-3)\n\n#### Java HttpsURLConnection \u003ca name=\"java-httpsurlconnection\"\u003e\u003c/a\u003e\n```java\nCharset charset = StandardCharsets.UTF_8;\nURL url = new URL(\"https://sandbox.api.mastercard.com/service\");\nString payload = \"{\\\"foo\\\":\\\"bar\\\"}\";\n\nHttpsURLConnection con = (HttpsURLConnection)url.openConnection();\ncon.setRequestMethod(\"POST\");\ncon.setRequestProperty(\"Content-Type\", \"application/json; charset=\" + charset.name());\n\nHttpsUrlConnectionSigner signer = new HttpsUrlConnectionSigner(charset, consumerKey, signingKey);\nsigner.sign(con, payload);\n```\n\n#### Apache HTTP Client 4 \u003ca name=\"apache-http-client-4\"\u003e\u003c/a\u003e\n```java\nString payload = \"{\\\"foo\\\":\\\"bar\\\"}\";\n\nHttpClient httpClient = HttpClientBuilder.create().build();\nHttpPost httpPost = new HttpPost(\"https://sandbox.api.mastercard.com/service\");\nhttpPost.setEntity(new StringEntity(payload, ContentType.APPLICATION_JSON));\n\nApacheHttpClient4Signer signer = new ApacheHttpClient4Signer(consumerKey, signingKey);\nsigner.sign(httpPost);\n```\n\n#### OkHttp 3 \u003ca name=\"okhttp-3\"\u003e\u003c/a\u003e\n```java\nMediaType JSON = MediaType.parse(\"application/json; charset=utf-8\");\nString payload = \"{\\\"foo\\\":\\\"bar\\\"}\";\n\nOkHttpClient client = new OkHttpClient();\nRequestBody body = RequestBody.create(JSON, payload);\nRequest.Builder request = new Request.Builder()\n        .url(\"https://sandbox.api.mastercard.com/service\")\n        .post(body);\n\nOkHttpSigner signer = new OkHttpSigner(consumerKey, signingKey);\nsigner.sign(request);\n```\n\n### Integrating with OpenAPI Generator API Client Libraries \u003ca name=\"integrating-with-openapi-generator-api-client-libraries\"\u003e\u003c/a\u003e\n\n[OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator) generates API client libraries from [OpenAPI Specs](https://github.com/OAI/OpenAPI-Specification). \nIt provides generators and library templates for supporting multiple languages and frameworks.\n\nThe `com.mastercard.developer.interceptors` package will provide you with some request interceptor classes you can use when configuring your API client. These classes will take care of adding the correct `Authorization` header before sending the request.\n\nLibrary options currently supported for the `java` generator:\n+ [okhttp-gson](#okhttp-gson)\n+ [feign](#feign)\n+ [retrofit](#retrofit)\n+ [retrofit2](#retrofit2)\n+ [google-api-client](#google-api-client)\n\nSee also:\n* [OpenAPI Generator (maven Plugin)](https://mvnrepository.com/artifact/org.openapitools/openapi-generator-maven-plugin)\n* [OpenAPI Generator (executable)](https://mvnrepository.com/artifact/org.openapitools/openapi-generator-cli)\n* [CONFIG OPTIONS for java](https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/java.md)\n\n#### okhttp-gson \u003ca name=\"okhttp-gson\"\u003e\u003c/a\u003e\n##### OpenAPI Generator Plugin Configuration\n```xml\n\u003cconfiguration\u003e\n    \u003cinputSpec\u003e${project.basedir}/src/main/resources/openapi-spec.yaml\u003c/inputSpec\u003e\n    \u003cgeneratorName\u003ejava\u003c/generatorName\u003e\n    \u003clibrary\u003eokhttp-gson\u003c/library\u003e\n    \u003c!-- ... --\u003e\n\u003c/configuration\u003e\n```\n\n##### Usage of the `OkHttp2OAuth1Interceptor` (OpenAPI Generator 3.3.x)\n```java\nApiClient client = new ApiClient();\nclient.setBasePath(\"https://sandbox.api.mastercard.com\");\nList\u003cInterceptor\u003e interceptors = client.getHttpClient().interceptors();\ninterceptors.add(new OkHttp2OAuth1Interceptor(consumerKey, signingKey));\nServiceApi serviceApi = new ServiceApi(client);\n// ...\n```\n\n##### Usage of the `OkHttpOAuth1Interceptor` (OpenAPI Generator 4+)\n```java\nApiClient client = new ApiClient();\nclient.setBasePath(\"https://sandbox.api.mastercard.com\");\nProxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(\"https://proxy-url.com\", 8866)); // Optional Proxy Configuration\nclient.setHttpClient(\n    client.getHttpClient()\n        .newBuilder()\n        .proxy(proxy) // Optional proxy\n        .addInterceptor(new OkHttpOAuth1Interceptor(consumerKey, signingKey))\n        .build()\n);\nServiceApi serviceApi = new ServiceApi(client);\n// ...\n```\n\n#### feign \u003ca name=\"feign\"\u003e\u003c/a\u003e\n##### OpenAPI Generator Plugin Configuration\n```xml\n\u003cconfiguration\u003e\n    \u003cinputSpec\u003e${project.basedir}/src/main/resources/openapi-spec.yaml\u003c/inputSpec\u003e\n    \u003cgeneratorName\u003ejava\u003c/generatorName\u003e\n    \u003clibrary\u003efeign\u003c/library\u003e\n    \u003c!-- ... --\u003e\n\u003c/configuration\u003e\n```\n\n##### Usage of the `OpenFeignOAuth1Interceptor`\n```java\nApiClient client = new ApiClient();\nclient.setBasePath(\"https://sandbox.api.mastercard.com\");\nFeign.Builder feignBuilder = client.getFeignBuilder();\nArrayList\u003cRequestInterceptor\u003e interceptors = new ArrayList\u003c\u003e();\ninterceptors.add(new OpenFeignOAuth1Interceptor(consumerKey, signingKey, client.getBasePath()));\nfeignBuilder.requestInterceptors(interceptors);\nServiceApi serviceApi = client.buildClient(ServiceApi.class);\n// ...\n```\n\n#### retrofit \u003ca name=\"retrofit\"\u003e\u003c/a\u003e\n##### OpenAPI Generator Plugin Configuration\n```xml\n\u003cconfiguration\u003e\n    \u003cinputSpec\u003e${project.basedir}/src/main/resources/openapi-spec.yaml\u003c/inputSpec\u003e\n    \u003cgeneratorName\u003ejava\u003c/generatorName\u003e\n    \u003clibrary\u003eretrofit\u003c/library\u003e\n    \u003c!-- ... --\u003e\n\u003c/configuration\u003e\n```\n\n##### Usage of the `OkHttp2OAuth1Interceptor`\n```java\nApiClient client = new ApiClient();\nRestAdapter.Builder adapterBuilder = client.getAdapterBuilder();\nadapterBuilder.setEndpoint(\"https://sandbox.api.mastercard.com\"); \nList\u003cInterceptor\u003e interceptors = client.getOkClient().interceptors();\ninterceptors.add(new OkHttp2OAuth1Interceptor(consumerKey, signingKey));\nServiceApi serviceApi = client.createService(ServiceApi.class);\n// ...\n```\n\n#### retrofit2 \u003ca name=\"retrofit2\"\u003e\u003c/a\u003e\n##### OpenAPI Generator Plugin Configuration\n```xml\n\u003cconfiguration\u003e\n    \u003cinputSpec\u003e${project.basedir}/src/main/resources/openapi-spec.yaml\u003c/inputSpec\u003e\n    \u003cgeneratorName\u003ejava\u003c/generatorName\u003e\n    \u003clibrary\u003eretrofit2\u003c/library\u003e\n    \u003c!-- ... --\u003e\n\u003c/configuration\u003e\n```\n\n##### Usage of the `OkHttpOAuth1Interceptor`\n```java\nApiClient client = new ApiClient();\nRetrofit.Builder adapterBuilder = client.getAdapterBuilder();\nadapterBuilder.baseUrl(\"https://sandbox.api.mastercard.com\"); \nOkHttpClient.Builder okBuilder = client.getOkBuilder();\nokBuilder.addInterceptor(new OkHttpOAuth1Interceptor(consumerKey, signingKey));\nServiceApi serviceApi = client.createService(ServiceApi.class);\n// ...\n```\n\n#### google-api-client \u003ca name=\"google-api-client\"\u003e\u003c/a\u003e\n##### OpenAPI Generator Plugin Configuration\n```xml\n\u003cconfiguration\u003e\n    \u003cinputSpec\u003e${project.basedir}/src/main/resources/openapi-spec.yaml\u003c/inputSpec\u003e\n    \u003cgeneratorName\u003ejava\u003c/generatorName\u003e\n    \u003clibrary\u003egoogle-api-client\u003c/library\u003e\n    \u003c!-- ... --\u003e\n\u003c/configuration\u003e\n```\n\n##### Usage of the `HttpExecuteOAuth1Interceptor`\n```java\nHttpRequestInitializer initializer = new HttpRequestInitializer() {\n    @Override\n    public void initialize(HttpRequest request) {\n        request.setInterceptor(new HttpExecuteOAuth1Interceptor(consumerKey, signingKey));\n    }\n};\nApiClient client = new ApiClient(\"https://sandbox.api.mastercard.com\", null, initializer, null);\nServiceApi serviceApi = client.serviceApi();\n// ...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmastercard%2Foauth1-signer-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmastercard%2Foauth1-signer-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmastercard%2Foauth1-signer-java/lists"}