OAuth Authorization Mode
PutEmail can use OAuth2. The exact way may depend on the email provider.
OAuth with Gmail
Configure Gmail OAuth Client
The Gmail OAuth client can be used to send email on behalf of multiple different gmail accounts so this needs to be done once.
- In the Google Development Console Create a project (if you don't have one yet)
- Configure OAuth consent
Create OAuth client. Select Desktop app as Application type.
When the client has been created, take note of the Client ID and Client secret values as they will be needed later.
Retrieve Token for NiFi
Tokens are provided once the owner of the Gmail account consented to the previously created client to send emails on their behalf.
Consequently, this needs to be done for every gmail account.
- Go to the following web page:
Replace CLIENT_ID at the end to your Client ID.
- You may need to select the Google Account for which you want to consent. Click Continue twice.
A page will appear with an Authorisation code that will have a message at the bottom like this:
Please copy this code, switch to your application and paste it there:
Execute the following command from terminal to fetch the access and refresh tokens.
In case the curl command returns an error, please try again from step 1.
curl https://accounts.google.com/o/oauth2/token -d grant_type=authorization_code -d redirect_uri="urn:ietf:wg:oauth:2.0:oob" -d client_id=CLIENT_ID -d client_secret=CLIENT_SECRET -d code=AUTHORISATION_CODE
Replace CLIENT_ID, CLIENT_SECRET and AUTHORISATION_CODE to your values.
The curl command results a json file which contains the access token and refresh token:
Configure Token in NiFi
On the PutEmail processor in the Authorization Mode property select Use OAuth2.
In the OAuth2 Access Token Provider property select/create a StandardOauth2AccessTokenProvider controller service.
On the StandardOauth2AccessTokenProvider controller service in the Grant Type property select Refresh Token.
In the Refresh Token property enter the REFRESH_TOKEN returned by the curl command.
In the Authorization Server URL enter
- Also fill in the Client ID and Client secret properties.