You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some providers require OAuth requests (including the token request and subsequent API calls) to be sender‑constrained using mutual TLS (mTLS). With this gem, you enable mTLS by providing a client certificate/private key to Faraday via connection_opts.ssl and, if your provider requires it for client authentication, selecting the tls_client_auth auth_scheme.
919
+
920
+
Example using PEM files (certificate and key):
921
+
922
+
```ruby
923
+
require"oauth2"
924
+
require"openssl"
925
+
926
+
client =OAuth2::Client.new(
927
+
ENV.fetch("CLIENT_ID"),
928
+
ENV.fetch("CLIENT_SECRET"),
929
+
site:"https://example.com",
930
+
authorize_url:"/oauth/authorize/",
931
+
token_url:"/oauth/token/",
932
+
auth_scheme::tls_client_auth, # if your AS requires mTLS-based client authentication
# verify: true # enable server cert verification (recommended)
940
+
},
941
+
},
942
+
)
943
+
944
+
# Example token request (any grant type can be used). The mTLS handshake
945
+
# will occur automatically on HTTPS calls using the configured cert/key.
946
+
access = client.client_credentials.get_token
947
+
948
+
# Subsequent resource requests will also use mTLS on HTTPS endpoints of `site`:
949
+
resp = access.get("/v1/protected")
950
+
```
951
+
952
+
Notes:
953
+
- Files must contain the appropriate PEMs. The private key may be encrypted; if so, pass a password to OpenSSL::PKey::RSA.new(File.read(path), ENV["KEY_PASSWORD"]).
954
+
- If your certificate and key are in a PKCS#12/PFX bundle, you can load them like:
- If your environment does not have system CAs, specify ca_file or ca_path inside the ssl: hash.
959
+
- Keep verify: true in production. Set verify: false only for local testing.
960
+
- Faraday adapter: Any adapter that supports Ruby’s OpenSSL should work. net_http (default) and net_http_persistent are common choices.
961
+
- Scope of mTLS: The SSL client cert is applied to any HTTPS request made by this client (token and resource requests) to the configured site base URL (and absolute URLs you call with the same client).
962
+
- OIDC tie-in: Some OPs require tls_client_auth at the token endpoint per OIDC/OAuth specifications. That is enabled via auth_scheme: :tls_client_auth as shown above.
0 commit comments