OAUTH2 & GOOGLE API PART II
September 21, 2017 ? Ualter Azambuja Junior

OAUTH2 & GOOGLE API PART II

In the first part of this article we have seen an introduction regard some basic concepts of this industry-standard framework called OAuth 2.0 (Open Authorization), a framework for authentication and authorization based on Tokens. We also went through an exercise of coding an example (using Gmail API Service and NodeJS) of one of its authorization grant type, the Authorization Code (a three-legged authentication scenario).

Now, at this Part II of our OAuth 2.0 journey, we are going to code an example of the two-legged authentication scenario using the Client Credentials grant type, one of those available by the specification. (See the little theoretical introduction of OAuth 2.0 framework at the Part I, in case you are not understanding very well what we are saying here).

Let’s use the Google Cloud Pub/Sub API Service to write our example, simulating our Application (playing the role of “Client” 3rd-Party Application), using the services provided by this API. Just for a matter of better understanding, and also in order you don’t need to go back to Part I and see what is (and the purpose of) the Google Cloud Pub/Sub API, we will put here the little presentation of it, the same written before:

Google Cloud Pub/Sub API Service (https://cloud.google.com/pubsub/)

  • This Google Cloud Service is an event base data stream system, useful to exchange information between consumers and providers in a stream using the very old (reliable and scalable) concept of messaging. It is not a surprise that the name of this cloud service is Pub/Sub. That rings a bell, doesn’t it?
  • In order to be able to use this API Service, we need before require the authorization (as well perform the authentication) and for this happens, we will use the OAuth 2.0 through the Client Credentials authorization grant type, provided by the Google Cloud Pub/Sub API Service.

Client Credentials Authorization Grant Type

As stated before, now at this scenario we are going to use the two-legged authentication, a typical scenario where it is not possible, or not convenient, to have the presence of the “User” (Resource Owner), to give the consent of the authorization all the time, in a online manner. As in a Server-to-Server communication… imagine that part of your Application needs to interact with some API Service to perform a job, on behalf of the user, at some time that he/she is not present, a scheduled job for instance at three o’clock in the morning, or a event-based communication (that triggers some action when something happens, like a message being received in a queue).

It is worth to mention (again)… as we said at the Part I regarding Client Credentials that:  this authorization grant type is typically used when the “Client” (3rd-Party Application) is also the “User” (Resource Owner), and it is performing an action on its own behalf, or… is requesting access to protected resources based on an authorization previously agreed with the “API Server” (Authorization Server).

Revisiting the generic flow of this framework, in this scenario the communication would go like this:

Having said all that, let’s use the Client Credentials authorization grant type in our example.

But, wait! Before dive into our code we have to perform some steps, in order that our Application be able to use the Client Credentials grant type, with the Google API Service. We need to create another type of credential at the Google Developer Console API, we need to create a Service Account.


The whole article, source code and everything else, available at...

https://ualterazambuja.com/2017/09/21/oauth2-google-api-part-ii/


要查看或添加评论,请登录

Ualter Otoni Pereira的更多文章

  • AWS Terraform Snitcher

    AWS Terraform Snitcher

    Snitch (chivato in Spanish, “dedo-duro” in slang Portuguese), if you usually watch CNN, mainly political subjects…

  • KUBERNETES OPERATORS IN GO

    KUBERNETES OPERATORS IN GO

    An Operator is a software application written to run over Kubernetes, extending its functionalities to manage other…

  • Microservices: Quarkus vs. Spring Boot

    Microservices: Quarkus vs. Spring Boot

    In the era of containers (the “Docker Age“) Java still keeps alive, being struggling for it or not. Java has always…

    3 条评论
  • AWS ECS EC2, Cloud & Containers, Part II

    AWS ECS EC2, Cloud & Containers, Part II

    In this two-part article about Cloud and Containers working together, here in the second part we will try out the AWS…

    1 条评论
  • AWS ECS Fargate, Cloud & Containers, Part I

    AWS ECS Fargate, Cloud & Containers, Part I

    Let’s talk about Cloud and Containers working together, in this article we’ll see (in practice) how to run, scale and…

  • BUILDING A CRYPTOCURRENCY WITH BLOCKCHAIN

    BUILDING A CRYPTOCURRENCY WITH BLOCKCHAIN

    If you have a cryptocurrency, then you own something digitally, you have an asset, considered to be a coin because it…

    1 条评论
  • REACTIVE PROGRAMMING WITH SPRING WEBFLUX

    REACTIVE PROGRAMMING WITH SPRING WEBFLUX

    REACTIVE PROGRAMMING Recently we are frequently hearing about a new paradigm of coding that is gaining more and more…

  • OAUTH2 & GOOGLE API PART I

    OAUTH2 & GOOGLE API PART I

    OAuth 2.0, commonly pronounced “oh-auth”, is an industry-standard framework for *authentication and *authorization…

  • Web Services Asynchronous

    Web Services Asynchronous

    Perhaps something very different and weird to see around is an asynchronous web services, but yes! This beast really…

  • Messaging Request/Reply

    Messaging Request/Reply

    Messaging Integration Style Fire-and-Forget Pattern When we think integration using messaging style, what usually comes…

    1 条评论

社区洞察

其他会员也浏览了