Through broker.oauth.*services, Mat|r offers authorization methods using OAuth2 protocol.

Moreover, it provides OAuth data type as an integrated model, where all the necessary fields involved in OAuth2 protocol are configured.

Model OAuth {
  String clientID
  String secret
  String authorizationURL
  String tokenURL
  String redirectURL
  String accountName
}

PUBLIC METHODS

String broker.oauth.authenticate(OAuth oauthConf)

It perform OAuth2 authorization, using the parameters set up in oauthConf and returns a token.

Parameter  
oauthConf OAuth: configuration of OAuth parameters.
Return  
String It returns a token if the authorization was successful. Otherwise, it returns null.

Example:

In the following example, we can see how our OAuth model is configured to obtain the authorization from facebook app. Firstly, we need to register a Facebook app. Afterwards, we must set some values typical of Facebook application such as cliendId and secret (values autogenerated by the app) and the URLs.

Rule login {
    OAuth fbOAuth = OAuth()
    //clientID and secret are fields generated by facebook
    fbOAuth.clientID = "110429725963xxxx"
    fbOAuth.secret = "8fc0392d9624db955147d36e26xxxxxx"

    //accountName: field used internally by mat|r to persist session info
    fbOAuth.accountName = "MyAccountFacebook"

    //authorizationURL y tokenURL: are provided in the facebook API documentation
    //the api version to connect with must be the same to the version is informed on the facebook app configuration screen
    fbOAuth.authorizationURL = "https://www.facebook.com/v2.9/dialog/oauth?scope=email"
    fbOAuth.tokenURL = "https://graph.facebook.com/v2.9/oauth/access_token"

    //redirect URL: here you must enter a custom URL as it is established by the oauth2 protocol
    fbOAuth.redirectURL = "http://mywebpage/auth/callback"

    //oauth2 authorize call is made, and in case of success a valid token is fetched
    tokenOAuth = broker.oauth.authenticate(fbOAuth)

    //once the authorization is granted, the variable 'tokenOAuth' can be used in all the endpoints which need a valid token
    ...
}