Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated to use the Go weekly for 11-02-11.

  • Loading branch information...
commit 19185dace3e30fa11df4911ca0a11426261b77f1 1 parent 74a9668
@paddyforan paddyforan authored
Showing with 21 additions and 23 deletions.
  1. +6 −6 authrequest.go
  2. +6 −6 verify.go
  3. +9 −11 yadis.go
View
12 authrequest.go
@@ -5,9 +5,9 @@
package openid
import (
+ "errors"
"strings"
"io"
- "os"
"url"
)
@@ -17,14 +17,14 @@ const (
IdentifierURL
)
-func GetRedirectURL(Identifier string, realm string, returnto string) (string, os.Error) {
- var err os.Error
+func GetRedirectURL(Identifier string, realm string, returnto string) (string, error) {
+ var err error
var Id, IdType = NormalizeIdentifier(Identifier)
// If the identifier is an XRI, [XRI_Resolution_2.0] will yield an XRDS document that contains the necessary information. It should also be noted that Relying Parties can take advantage of XRI Proxy Resolvers, such as the one provided by XDI.org at http://www.xri.net. This will remove the need for the RPs to perform XRI Resolution locally.
if IdType == IdentifierXRI {
// Not implemented yet
- return "", os.NewError("XRI identifier not implemented yed")
+ return "", errors.New("XRI identifier not implemented yed")
}
// If it is a URL, the Yadis protocol [Yadis] SHALL be first attempted. If it succeeds, the result is again an XRDS document.
@@ -35,12 +35,12 @@ func GetRedirectURL(Identifier string, realm string, returnto string) (string, o
return "", err
}
if reader == nil {
- return "", os.NewError("Yadis returned an empty Reader for the ID: " + Id)
+ return "", errors.New("Yadis returned an empty Reader for the ID: " + Id)
}
var endpoint, claimedid = ParseXRDS(reader)
if len(endpoint) == 0 {
- return "", os.NewError("Unable to parse the XRDS document")
+ return "", errors.New("Unable to parse the XRDS document")
}
// At this point we have the endpoint and eventually a claimed id
View
12 verify.go
@@ -5,8 +5,8 @@
package openid
import (
+ "errors"
"log"
- "os"
"http"
"regexp"
"bytes"
@@ -18,7 +18,7 @@ import (
// * true if authenticated, false otherwise
// * The Claimed identifier if authenticated
// * Eventually an error
-func Verify(url_ string) (grant bool, identifier string, err os.Error) {
+func Verify(url_ string) (grant bool, identifier string, err error) {
grant = false
identifier = ""
err = nil
@@ -45,7 +45,7 @@ var REVerifyDirectIsValid = "is_valid:true"
var REVerifyDirectNs = regexp.MustCompile("ns:([a-zA-Z0-9:/.]*)")
// Like Verify on a parsed URL
-func VerifyValues(values url.Values) (grant bool, identifier string, err os.Error) {
+func VerifyValues(values url.Values) (grant bool, identifier string, err error) {
err = nil
var postArgs url.Values
@@ -55,7 +55,7 @@ func VerifyValues(values url.Values) (grant bool, identifier string, err os.Erro
URLEndPoint := values.Get("openid.op_endpoint")
if URLEndPoint == "" {
log.Printf("no openid.op_endpoint")
- return false, "", os.NewError("no openid.op_endpoint")
+ return false, "", errors.New("no openid.op_endpoint")
}
for k, v := range values {
postArgs[k] = v
@@ -85,11 +85,11 @@ func VerifyValues(values url.Values) (grant bool, identifier string, err os.Erro
// Check for ns
rematch := REVerifyDirectNs.FindSubmatch(buffer)
if rematch == nil {
- return false, "", os.NewError("VerifyValues: ns value not found on the response of the OP")
+ return false, "", errors.New("VerifyValues: ns value not found on the response of the OP")
}
nsValue := string(rematch[1])
if !bytes.Equal([]byte(nsValue), []byte("http://specs.openid.net/auth/2.0")) {
- return false, "", os.NewError("VerifyValues: ns value not correct: " + nsValue)
+ return false, "", errors.New("VerifyValues: ns value not correct: " + nsValue)
}
// Check for is_valid
View
20 yadis.go
@@ -5,7 +5,7 @@
package openid
import (
- "os"
+ "errors"
"http"
"url"
"io"
@@ -16,11 +16,11 @@ import (
"strings"
)
-func Yadis(ID string) (io.Reader, os.Error) {
+func Yadis(ID string) (io.Reader, error) {
return YadisVerbose(ID, nil)
}
-func YadisVerbose(ID string, verbose *log.Logger) (io.Reader, os.Error) {
+func YadisVerbose(ID string, verbose *log.Logger) (io.Reader, error) {
r, err := YadisRequest(ID, "GET")
if err != nil || r == nil {
return nil, err
@@ -64,7 +64,7 @@ func YadisVerbose(ID string, verbose *log.Logger) (io.Reader, os.Error) {
return nil, nil
}
-func YadisRequest(url_ string, method string) (resp *http.Response, err os.Error) {
+func YadisRequest(url_ string, method string) (resp *http.Response, err error) {
resp = nil
var request = new(http.Request)
@@ -72,7 +72,6 @@ func YadisRequest(url_ string, method string) (resp *http.Response, err os.Error
var Header = make(http.Header)
request.Method = method
- request.RawURL = url_
request.URL, err = url.Parse(url_)
if err != nil {
@@ -98,16 +97,15 @@ func YadisRequest(url_ string, method string) (resp *http.Response, err os.Error
}
if response.StatusCode == 301 || response.StatusCode == 302 || response.StatusCode == 303 || response.StatusCode == 307 {
location := response.Header.Get("Location")
- request.RawURL = location
request.URL, err = url.Parse(location)
if err != nil {
- return
+ return nil, err
}
} else {
return response, nil
}
}
- return nil, os.NewError("Too many redirections")
+ return nil, errors.New("Too many redirections")
}
var metaRE *regexp.Regexp
@@ -123,18 +121,18 @@ func init() {
xrdsRE = regexp.MustCompile("[cC][oO][nN][tT][eE][nN][tT]=[\"']([^\"]+)[\"']")
}
-func searchHTMLMetaXRDS(r io.Reader) (string, os.Error) {
+func searchHTMLMetaXRDS(r io.Reader) (string, error) {
data, err := ioutil.ReadAll(r)
if err != nil {
return "", err
}
part := metaRE.Find(data)
if part == nil {
- return "", os.NewError("No -meta- match")
+ return "", errors.New("No -meta- match")
}
content := xrdsRE.FindSubmatch(part)
if content == nil {
- return "", os.NewError("No content in meta tag: " + string(part))
+ return "", errors.New("No content in meta tag: " + string(part))
}
return string(content[1]), nil
}
Please sign in to comment.
Something went wrong with that request. Please try again.