gitea源码

openid.go 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package openid
  4. import (
  5. "time"
  6. "github.com/yohcop/openid-go"
  7. )
  8. // For the demo, we use in-memory infinite storage nonce and discovery
  9. // cache. In your app, do not use this as it will eat up memory and
  10. // never
  11. // free it. Use your own implementation, on a better database system.
  12. // If you have multiple servers for example, you may need to share at
  13. // least
  14. // the nonceStore between them.
  15. var (
  16. nonceStore = openid.NewSimpleNonceStore()
  17. discoveryCache = newTimedDiscoveryCache(24 * time.Hour)
  18. )
  19. // Verify handles response from OpenID provider
  20. func Verify(fullURL string) (id string, err error) {
  21. return openid.Verify(fullURL, discoveryCache, nonceStore)
  22. }
  23. // Normalize normalizes an OpenID URI
  24. func Normalize(url string) (id string, err error) {
  25. return openid.Normalize(url)
  26. }
  27. // RedirectURL redirects browser
  28. func RedirectURL(id, callbackURL, realm string) (string, error) {
  29. return openid.RedirectURL(id, callbackURL, realm)
  30. }