Coder Social home page Coder Social logo

talxis / token-proxy Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 18 KB

Token Proxy allows the use of client_credentials grant in Logic Apps/Power Automate connectors via Basic Authentication headers and proxying the request to target.

License: MIT License

C# 100.00%
client-credentials-grant power-automate logic-apps-custom-connector logic-apps oauth2 basic-authentication

token-proxy's Introduction

Token Proxy

Token Proxy allows the use of client_credentials grant in Logic Apps/Power Automate connectors via Basic Authentication headers and acting as a proxy to the target API.

The primary point is to provide the ability to use client_credentials flow in Custom Connectors, which is not officially supported by Microsoft (if you need to authenticate with client_credentials against your own API protected with Azure AD, there is a native way to do this, blog post will eventually be made, however this tool can also be used to authenticate against Azure AD via client_credentials flow).

As previously mentioned, this solution acts as a proxy which accepts the client_credentials as Basic authentication (username = clientId, password = clientSecret). While we know it is not an optimal solution, it appears to be the only solution to do this against custom OAuth2 / OpenID Connect provider. Also the extra benefit is, that the acquired token can be cached for the specified amount of time, so you won't hit your STS with every single request.

Alternatively, you can provide both clientId and clientSecret as query parameters = $clientId and $clientSecret. This has been added due to the need to access multiple workspaces in a single Flow dynamically.

There is an open issue in Microsoft's custom connectors repository to provide the documentation on how-to achieve this natively with connectors (yes, it is possible, at least with Azure AD).

Getting started

  1. Deploy to Azure as an Azure Function app
  2. Configure settings (example below)
"BaseUrl": "https://petstore.swagger.io",
"TokenEndpoint": "https://petstore.swagger.io/oauth/token",
"Scope": "api.read api.write"

Optionally you can configure token cache TTL (default value is 30 minutes)

"TokenCacheTime": "0:15:00" // set to 15 minutes
  1. Change the base url in your custom connector definition to https://{your-function-app-name}.azurewebsites.net/Proxy

Example usage

Every Custom connector action should now work as expected. For example the action GET /pet/{petId} from the original connector will now be:

  1. Logic Apps/Power Automate sends request to https://{your-function-app-name}.azurewebsites.net/Proxy/pet/{petId}
  2. Basic authentication will be used as client credentials to acquire the access token
    • You can then configure Basic authentication as a method for your Flow/Logic Apps custom connector.
  3. The token is cached for future use with identical client credentials
  4. The token is attached to the incoming request and sent along to /pet/{petId}
  5. The response is then forwarded back to your Logic Apps/Power Automate

token-proxy's People

Contributors

dk-klein avatar hajekj avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

xhacksbro

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.