How to connect to outlook.office365.com with POP3 by using OAuth2 - oauth-2.0

Currently we have a Spring Integration application using a mail inbound channel adapter for receiving and processing application emails. It connects to Outlook 365 using POP3 protocol using basic authentication with a user/password. Since Basic Authentication is being discontinued by Microsoft later this year we are required to migrate the authentication to OAUTH2 (Modern Authentication) token based access. In this regard my question is as follows:
<int-mail:inbound-channel-adapter id="pop3Adater"
store-uri="pop3s://user:password#pop3serverhost/Inbox"
java-mail-properties=""
/>
The POP3 store-uri is
pop3s://user:password#pop3serverhost/Inbox
How should the store-uri be modified to use oauth access token for autehtication? (We will only have an AZURE Base64 encoded access token)
Any help in this regard is greatly appreciated.

Related

Using JWT to authorize REST API requests after SAML Authentication

I'm struggling theese days on the possible way to configure an Authentication + authorization system to consume a REST API from a mobile application.
Scenario:
We've developed 3 independent portals for a big customer that serves several users.
To enable a SSO for the 3 portals we've implemented a SAML authentication system using SimpleSAMLphp.
Every portal has a service provider and they make assertion requests against a central IdP.
The IdP checks username and password against a database where passwords are hashed and stored during registration.
After the login, the authorization on the portals is handled by the session on the server, and so far everything was fine.
Now the customer asked us to develop a mobile application that will require the users to login and access several of their protected resources collected during the usage of the 3 portals.
We've decided to develop a frontend application using ionic that will consume a REST API made in node.js that will serve all the data (both protected and unprotected resources).
Now here comes the question: to authorize access to protected resources on the Api we'd like to use JWT to easily achieve a stateless system.
The doubt is how to perform the authentication? We've the opportunity to check the credentials directly against the database skipping the SAML process, otherwise we've to implement a solution where the SSO IdP acts as authentication provider and then when an attempt is successful the API app will get the response from the idp and then issue a signed jwt to the consumer client. Is this second way a common implementation? Is it possible?
What path do you suggest to follow? The first could be very easy to achieve, but since we're using html+js for the app's frontend, if we decide to use the second solution probably in the near future we could recycle some code from the app to modernize some functions on the web portals, maintaining the jwt pattern and consuming the new Api also on the web.
I believe that in this case will be easier to ask a token to the new api using someway the logged in user's data already in the session of the portal. Sounds possible?
I hope that everything was clear, any help will be appreciated!
Thanks
The key goal here is to code your apps in the best way, via
the latest security standards (OAuth 2.0 and Open Id Connect).
SAML is an outdated protocol that is not web / mobile / API friendly, and does not fit with modern coding models.
Sounds like you want to do OAuth but you do not have an OAuth Authorization Server, which is a key part of the solution. If you could migrate to one you would have the best future options for your apps.
OPTION 1
Use the most standard and simple option - but users have to login with a new login screen + credentials:
Mobile or Web UI uses Authorization Flow (PKCE) and redirects to an Authorization Server to sign the user in
Mobile or Web UI receives an access token after login that can be sent to the API
Access token format is most commonly a JWT that the API can validate and identify the user from
The API is not involved in the login or token issuing processes
OPTION 2
Extend option 1 to federate to your SAML Identity Provider - enables users to login in the existing way:
The Authorization Server is configured to trust your SAML based identity provider and to redirect to it during logins
The SAML idp presents a login screen and then posts a SAML token to the Authorization Server
The Authorization Server issues OAuth based tokens based on the SAML token details
OPTION 3
Use a bridging solution (not really recommended but sometimes worth considering if you have no proper authorization server - at least it gets your apps using OAuth tokens):
Mobile or Web UI uses Resource Owner Password Grant and sends credentials to a new OAuth endpoint that you develop
OAuth endpoint provides a /oauth/token endpoint to receive the request
OAuth endpoint checks the credentials against the database - or translates to a SAML request that is forwarded to the IDP
OAuth endpoint does its own issuing of JWT access tokens via a third party library (if credentials are valid)
Web or Mobile UI sends JWT access token to API
API validates received JWT access token

Slack client secret for OAuth in mobile application

There seems to be an inconsistency in the Slack API docs in that the OAuth flow requires a client_secret be provided as part of the exchange of the code for the OAuth token as documented at https://api.slack.com/methods/oauth.access
However the client secret then needs to be embedded into the mobile app which goes against Slack's recommendations at https://api.slack.com/docs/oauth-safety which states:
Your Client Secret should be treated delicately. It is how you securely identify your application's rights and identity when exchanging tokens with Slack. Do not distribute client secrets in email, distributed native applications, client-side javascript, or public code repositories.
Are there any best practices available in terms of how to manage this discrepancy where the client secret seems to be required for auth but at the same time should not be embedded into the mobile app?
Slack only supports the Authorisation Code Flow for OAuth2.0 but it doesn't support public clients only confidential clients. It doesn't support the PKCE flow either.
Their FAQ page suggests using the RTM API if you a re developing a mobile app:

How to generate access token for OAuth authentication using the available Client ID and Client Secret for GMail API (IMAP)

I have generated a Client ID and Client Secret for my application using the Google API Console for my Java web application.
I want to generate an access token to be used in my application to authenticate a mailbox and read mails from there with the help of JavaMail API.
This link has some theoretical information but I could not understand how the tokens can be obtained.
Answer will depend upon where is application running as it determines how access token can be received:
Using OAuth 2.0 for Web Server Applications
OAuth 2.0 for Client-side
Web Applications OAuth 2.0 for Mobile & Desktop Apps
OAuth 2.0 for TV and Limited-Input Device Applications
There are different alternatives or libraries available to get access token depending upon the type of application and different specific mechanisms are defined around it.
So it will be then much easier to dive-in into the specific options available.

Do OAuth 1 tokens work with Gmail API?

Gmail released a new API and since the auth scope is the same as for IMAP, it looks like IMAP access tokens will work on the Gmail API.
What is unclear is if OAuth 1 tokens will work on the Gmail API. I have legacy OAuth 1 tokens I'm considering migrating from IMAP to the Gmail API but I cannot ask the users to update their credentials.
Gmail API does not support the deprecated Oauth1 standard. A forward-path for upgrading those tokens to Oauth2 (without user involvement) can be found:
https://developers.google.com/accounts/docs/OAuth_ref#migration

Consume SalesForce over OAuth 2.0

I am using DotNetOpenAuth libraries to implement OAuth 2.0 client side to communicate with SalesForce authorization server. I have finished first two steps of OAuth 2.0 communication that ends with obtaining of access token from SalesForce authorization server.
Now I want to get some resource form SF. Is that possible only over REST service infrastructure ? Can I can send http request with access token and specified parameter to be retrieved to SF ?
Thank you,
Rastko

Resources