Giter Site home page Giter Site logo

Comments (4)

pcantrell avatar pcantrell commented on May 18, 2024

There isn't a whole lot of public example code yet. You’ll find some hints in the configuration chapter of the user guide and in the API docs for invalidateConfiguration.

Although there isn’t currently time available for it, my hope to write up a cookbook of examples for the 1.0 release.

If you can pose a more specific question, I can help point you in the right direction.

from siesta.

joshhornby avatar joshhornby commented on May 18, 2024

The cookbook sounds great.

Question wise, how would you handle oAuth 2 with Siesta?

from siesta.

pcantrell avatar pcantrell commented on May 18, 2024

I’d first select a third-party lib such as p2/OAuth2 or dongri/OAuthSwift to handle the whole dance of acquiring an OAuth token. That's well outside the scope of Siesta.

Once you have a token, you’d do something like this:

class MyApi: Service
    {
    init()
        {
        ...

        configure { $0.config.headers["Authorization"] = authHeader }
        }

    var authHeader: String?
        {
        didSet
            {
            // Clear any cached data now that auth has changed
            wipeResources()

            // Force resources to recompute headers next time they’re fetched
            invalidateConfiguration()
            }
        }
    }

…and then when authentication succeeds:

myAPI.authToken = authTokenFromOAuthLib

…and for logout:

myAPI.authToken = nil

You could integrate OAuth more tightly with Siesta. For example, you could add special error handling hooks in your Siesta config to trigger a token refresh when you detect an OAuth error. However, I’d start with something as simple as the code above and see what other needs you have.

from siesta.

pcantrell avatar pcantrell commented on May 18, 2024

I added some of this info to the Siesta docs: http://bustoutsolutions.github.io/siesta/guide/security/

Closing this issue, but feel free to post more on Stack Overflow (with the siesta-swift tag) or here if you need more info.

from siesta.

Related Issues (20)

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.