({{, (RefLink[SecuredAuthenticationKey, paclet:ref/SecuredAuthenticationKey])[assoc] 
represents a secured authentication key with credentials and details specified by the association assoc.}})

OpenersNotesSection(Spacer1)Details

(RefLink[SecuredAuthenticationKey, paclet:ref/SecuredAuthenticationKey]) is a symbolic representation of OAuth credentials used in an authentication process; it does not itself perform authentication.

In (RefLink[SecuredAuthenticationKey, paclet:ref/SecuredAuthenticationKey])[assoc], assoc should have the following components:

The following additional entries can also be given in the association:

"OAuthType" supports the following workflows:

"CallbackURL" supports the following values:

"SignatureMethod" supports the following key-generation, hash-algorithm pairs:

Possible settings for "TransmissionMethod" include "Headers" and "Query".

(RefLink[URL, paclet:ref/URL])["url"] is also supported in the "RequestTokenURL", "AccessTokenURL" and "CallbackURL" fields.

OpenersPrimaryExamplesSection(Spacer1)Examples  (5)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Create a (RefLink[SecuredAuthenticationKey, paclet:ref/SecuredAuthenticationKey]) to authenticate a call to Flickr's test API using three-legged OAuth. Use your Flickr consumer key and secret to evaluate the example properly:

flickrConsumerKey="Flickr consumer key";
flickrConsumerSecret="Flickr consumer secret";

flickrKey=SecuredAuthenticationKey[<|"Name"->"Flickr",
"OAuthType"->"ThreeLegged",
"ConsumerKey"-> flickrConsumerKey,
"ConsumerSecret"-> flickrConsumerSecret,
"RequestTokenURL"->"https://www.flickr.com/services/oauth/request_token",
"AccessTokenURL"->"https://www.flickr.com/services/oauth/access_token",
"UserAuthorizationURL" ->"https://www.flickr.com/services/oauth/authorize",
"CallbackURL"->Automatic,
"SignatureMethod"->{"HMAC","SHA1"}|>
]

Check that the key is working:

URLExecute["https://api.flickr.com/services/rest",{"method"->"flickr.test.login","api_key"->flickrConsumerKey},Authentication->flickrKey]

Create a (RefLink[SecuredAuthenticationKey, paclet:ref/SecuredAuthenticationKey]) with credentials from an external service, using two-legged OAuth:

mykey = SecuredAuthenticationKey[<|"Name"->"MyAuthKey",
"ConsumerKey"-> "cwcq4v25eyivjddp6hlg",
"ConsumerSecret"-> "gg43zzp301nahhm2662f",
"RequestTokenURL"->"https://myservice.com/oauth/request_token",
"AccessTokenURL"->"https://myservice.com/oauth/access_token",
"SignatureMethod"->{"HMAC","SHA1"}|>]

Use the key to send signed requests to a service:

URLRead[HTTPRequest["https://myservice.com/api"],Authentication->mykey]

OpenersExampleSection1(Spacer1)Scope  (3)

OpenersExampleSubsection0(Spacer1)CallbackURL  (2)

OpenersExampleSubsubsection0(Spacer1)URL  (1)

Deploy a custom page to display the verifier code:

func=Delayed[HTTPRequestData["Query"]];
customCallbackURL=URL@@CloudDeploy[func,"CustomCallbackURL",Permissions->"Public"]

Use the URL in the (RefLink[SecuredAuthenticationKey, paclet:ref/SecuredAuthenticationKey]). Use your Flickr consumer key and secret to evaluate the example properly:

flickrConsumerKey="Flickr consumer key";
flickrConsumerSecret="Flickr consumer secret";

flickrKey=SecuredAuthenticationKey[<|"Name"->"Flickr2",
"OAuthType"->"ThreeLegged",
"ConsumerKey"-> flickrConsumerKey,
"ConsumerSecret"-> flickrConsumerSecret,
"RequestTokenURL"->"https://www.flickr.com/services/oauth/request_token",
"AccessTokenURL"->"https://www.flickr.com/services/oauth/access_token",
"UserAuthorizationURL" ->"https://www.flickr.com/services/oauth/authorize",
"CallbackURL"->URL[(URLArgument["https://www.wolframcloud.com/objects/documentation/CustomCallbackURL"])],
"SignatureMethod"->{"HMAC","SHA1"}|>
]

Check that the key is working:

URLExecute["https://api.flickr.com/services/rest",{"method"->"flickr.test.login","api_key"->flickrConsumerKey},Authentication->flickrKey]

OpenersExampleSubsubsection1(Spacer1)Inherited  (1)

Use (RefLink[Inherited, paclet:ref/Inherited]) to create a (RefLink[SecuredAuthenticationKey, paclet:ref/SecuredAuthenticationKey]) where the callback URL has been established separately with the service, or out of band. Use your Twitter consumer key and secret to evaluate the example properly:

twitterConsumerKey="Twitter consumer key";
twitterConsumerSecret="Twitter consumer secret";

SecuredAuthenticationKey[<|"Name"->"MyAuthKey",
"OAuthType"->"ThreeLegged",
"ConsumerKey"-> twitterConsumerKey,
"ConsumerSecret"-> twitterConsumerSecret,
"RequestTokenURL"->"https://api.twitter.com/oauth/request_token",
"AccessTokenURL"->"https://api.twitter.com/oauth/access_token",
"UserAuthorizationURL" ->"https://api.twitter.com/oauth/authorize",
"CallbackURL"->Inherited,
"SignatureMethod"->{"HMAC","SHA1"}|>]

OpenersExampleSubsection1(Spacer1)VerifierInputFunction  (1)

Create a key that uses a custom (RefLink[VerifierInputFunction, paclet:ref/VerifierInputFunction]). Use your Flickr consumer key and secret to evaluate the example properly:

flickrConsumerKey="Flickr consumer key";
flickrConsumerSecret="Flickr consumer secret";

SecuredAuthenticationKey[<|"Name"->"Flickr",
"OAuthType"->"ThreeLegged",
"ConsumerKey"-> flickrConsumerKey,
"ConsumerSecret"-> flickrConsumerSecret,
"RequestTokenURL"->"https://www.flickr.com/services/oauth/request_token",
"AccessTokenURL"->"https://www.flickr.com/services/oauth/access_token",
"UserAuthorizationURL" ->"https://www.flickr.com/services/oauth/authorize",
"CallbackURL"->Automatic,
"VerifierInputFunction"->(InputString["Enter your verifier here:"]&),
"SignatureMethod"->{"HMAC","SHA1"}|>
]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[GenerateSecuredAuthenticationKey, paclet:ref/GenerateSecuredAuthenticationKey])  ▪  (RefLink[SecuredAuthenticationKeys, paclet:ref/SecuredAuthenticationKeys])  ▪  (RefLink[Authentication, paclet:ref/Authentication])  ▪  (RefLink[PermissionsKey, paclet:ref/PermissionsKey])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Cloud Permissions Control, paclet:guide/CloudPermissionsControl])}, {▪(RefLinkPlain[Web Operations, paclet:guide/WebOperations])}, {▪(RefLinkPlain[URL Manipulation, paclet:guide/URLManipulation])}, {▪(RefLinkPlain[HTTP Requests & Responses, paclet:guide/HTTPRequestsAndResponses])}})}})