{"id":36243,"date":"2024-08-21T13:59:19","date_gmt":"2024-08-21T12:59:19","guid":{"rendered":"https:\/\/developers.ila.cegid.com\/valuekeep\/\/"},"modified":"2024-12-26T15:46:31","modified_gmt":"2024-12-26T14:46:31","slug":"webapi-how-does-the-oauth-2-0-authorization-work","status":"publish","type":"valuekeep","link":"https:\/\/developers.ila.cegid.com\/en\/valuekeep\/api-documentation-en\/web-api-en\/article\/webapi-how-does-the-oauth-2-0-authorization-work","title":{"rendered":"How does the OAUTH 2.0 authorization work?"},"content":{"rendered":"<section class=\"av_textblock_section \"  itemscope=\"itemscope\" itemtype=\"https:\/\/schema.org\/CreativeWork\" ><div class='avia_textblock  '   itemprop=\"text\" ><p class=\"MsoNormal\"><span style=\"font-size: 12pt; line-height: 107%; color: #333333;\">OAuth 2.0 is a standard authorization protocol that allows applications to access a user&#8217;s account in a web service (HTTP) such as the Valuekeep CMMS Web API.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 12pt; line-height: 107%; color: #333333;\">The protocol delegates user authentication to the service that holds the user&#8217;s account and authorizes external applications to access that user&#8217;s account. The protocol makes authorization flows available for Web, desktop and mobile apps.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 12pt; line-height: 107%; color: #333333;\">We now describe the basic operation of the protocol from the perspective of an application developer.<\/span><\/p>\n<h2>OAuth Roles<\/h2>\n<p class=\"MsoNormal\"><span style=\"font-size: 12pt; line-height: 107%; color: #333333;\">The protocol defines 4 roles:<\/span><\/p>\n<ol>\n<li class=\"MsoNormal\"><span style=\"font-size: 12pt;\"><b><span style=\"color: #333333;\">Resource owner<\/span><\/b><span style=\"color: #333333;\">: this is the user who authorizes the application&#8217;s access to his account. Such access is limited to the scope of the authorization given by the user.<\/span><\/span><\/li>\n<li class=\"MsoNormal\"><b style=\"font-size: 12pt; text-indent: -0.25in;\">Client<\/b><span style=\"color: #333333;\">: is the application that wants to access the user <\/span>account.<\/li>\n<li class=\"MsoNormal\"><b style=\"font-size: 12pt; text-indent: -0.25in;\">Resource server<\/b><span style=\"color: #333333;\">: is the server that hosts the user&#8217;s <\/span>accounts.<\/li>\n<li class=\"MsoNormal\"><b style=\"font-size: 12pt; text-indent: -0.25in;\">Authorization server<\/b><span style=\"color: #333333;\">: is the server that verifies the <\/span>identity of the user and assigns authorization tokens to the client (the application).<\/li>\n<\/ol>\n<p class=\"MsoNormal\"><span style=\"font-size: 12pt; line-height: 107%; color: #333333;\">From the point of view of an application developer, the Web API you want to consume acts both as resource server and the authorization server. It is, therefore, common for the two roles to be combined in what is called a Service or simply an API.<\/span><\/p>\n<h2 style=\"margin: 12pt 0in 12pt 0in;\">Generic authorization flow<\/h2>\n<p class=\"MsoNormal\"><span style=\"font-size: 12pt; line-height: 107%; color: #333333;\">The normal authorization flow from an external application will follow these steps:<\/span><\/p>\n<ol>\n<li class=\"MsoNormal\"><span style=\"font-size: 12pt;\"><span style=\"color: #333333;\">The application requests permission to access user resources.<\/span><\/span><\/li>\n<li class=\"MsoNormal\">If the user has already authorized such a request, the application receives an authorization grant.<\/li>\n<li class=\"MsoNormal\">The application asks the authorization server for an access token, showing the user&#8217;s identity and the authorization grant.<\/li>\n<li class=\"MsoNormal\">If the application&#8217;s identity is authenticated and the authorization grant is valid, the authorization server assigns an access token to the application and the authorization flow ends.<\/li>\n<li class=\"MsoNormal\">The application requests a certain resource from the resource server and displays the access token it obtained before.<\/li>\n<li class=\"MsoNormal\">If the access token is valid, the resource server will return the requested resource to the application.<\/li>\n<li class=\"MsoNormal\">This is OAuth&#8217;s normal conceptual flow, <span style=\"font-size: 12pt; text-indent: -0.25in;\">but the actual authentication flow depends on the type of authorization grant <\/span>that is used. We will now discuss the different authorization grants available.<\/li>\n<\/ol>\n<h2>Authorization Grant: Client credentials grant<\/h2>\n<p class=\"MsoNormal\"><span style=\"font-size: 12pt; line-height: 107%; color: #333333;\">The type of grant used depends on the authorization method the app wishes to use and, of course, of the methods supported by the Web API. To work with the Valuekeep CMMS Web API, you must use the Client Credentials authorization method.<\/span><\/p>\n<h2 style=\"margin: 12pt 0in 12pt 0in;\">Refresh Token<\/h2>\n<p class=\"MsoNormal\"><span class=\"size\" style=\"font-size: 12pt;\"><span style=\"color: #333333;\">When an access token expires, its use to perform requests to the API will result in the error \u201cInvalid Token Error\u201d. In that moment, if a refresh token has been included when the access token is generated, you can use it for a new server access token.<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span class=\"size\" style=\"font-size: 12pt;\"><span style=\"color: #333333;\">Example of a request of that type:<\/span><\/span><\/p>\n<div style=\"border: none; border-left: solid #cccccc 1.5pt; padding: 0in 0in 0in 2pt; background: whitesmoke; margin-left: 18.75pt; margin-right: 0.75pt;\">\n<p class=\"styl9ogsrcls\" style=\"text-indent: -0.25in; background: whitesmoke; border: none; padding: 0in; margin: 0.75pt 0in 0.75pt 0.25in;\"><span style=\"font-size: 12pt;\"><span style=\"color: #333333;\">1.<span style=\"font-style: normal; font-variant: normal; font-size-adjust: none; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-weight: normal; font-stretch: normal; line-height: normal; font-family: 'Times New Roman';\"><br \/>\n<\/span><\/span><span style=\"color: black;\"><a href=\"https:\/\/myserver.com\/v1\/oauth\/token?grant_type=refresh_token&amp;client_id=%7bClientId%7d&amp;client_secret=%7bClientSecret%7d&amp;refresh_token=%7bRefreshToken%7d%E2%80%8B\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/myserver.com\/v1\/oauth\/token?grant_type=refresh_token&amp;client_id={ClientId}&amp;client_secret={ClientSecret}&amp;refresh_token={RefreshToken}%E2%80%8B<\/a><\/span><\/span><\/p>\n<\/div>\n<div><\/div>\n<\/div><\/section>\n","protected":false},"excerpt":{"rendered":"","protected":false},"featured_media":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","format":"standard","tags":[840],"videos_tax":[],"post-type":[300],"categoria-valuekeep":[998],"class_list":["post-36243","valuekeep","type-valuekeep","status-publish","format-standard","hentry","tag-oauth","post-type-artigo","categoria-valuekeep-web-api-en"],"_links":{"self":[{"href":"https:\/\/developers.ila.cegid.com\/en\/wp-json\/wp\/v2\/valuekeep\/36243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/developers.ila.cegid.com\/en\/wp-json\/wp\/v2\/valuekeep"}],"about":[{"href":"https:\/\/developers.ila.cegid.com\/en\/wp-json\/wp\/v2\/types\/valuekeep"}],"replies":[{"embeddable":true,"href":"https:\/\/developers.ila.cegid.com\/en\/wp-json\/wp\/v2\/comments?post=36243"}],"version-history":[{"count":0,"href":"https:\/\/developers.ila.cegid.com\/en\/wp-json\/wp\/v2\/valuekeep\/36243\/revisions"}],"wp:attachment":[{"href":"https:\/\/developers.ila.cegid.com\/en\/wp-json\/wp\/v2\/media?parent=36243"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/developers.ila.cegid.com\/en\/wp-json\/wp\/v2\/tags?post=36243"},{"taxonomy":"videos_tax","embeddable":true,"href":"https:\/\/developers.ila.cegid.com\/en\/wp-json\/wp\/v2\/videos_tax?post=36243"},{"taxonomy":"post-type","embeddable":true,"href":"https:\/\/developers.ila.cegid.com\/en\/wp-json\/wp\/v2\/post-type?post=36243"},{"taxonomy":"categoria-valuekeep","embeddable":true,"href":"https:\/\/developers.ila.cegid.com\/en\/wp-json\/wp\/v2\/categoria-valuekeep?post=36243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}