id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
13,800 | coyim/otr3 | sexp/cons.go | List | func List(values ...Value) Value {
var result Value = snil
l := len(values)
for i := l - 1; i >= 0; i-- {
result = Cons{values[i], result}
}
return result
} | go | func List(values ...Value) Value {
var result Value = snil
l := len(values)
for i := l - 1; i >= 0; i-- {
result = Cons{values[i], result}
}
return result
} | [
"func",
"List",
"(",
"values",
"...",
"Value",
")",
"Value",
"{",
"var",
"result",
"Value",
"=",
"snil",
"\n",
"l",
":=",
"len",
"(",
"values",
")",
"\n\n",
"for",
"i",
":=",
"l",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
"result",
"=",
"Cons",
"{",
"values",
"[",
"i",
"]",
",",
"result",
"}",
"\n",
"}",
"\n\n",
"return",
"result",
"\n",
"}"
] | // List creates a chain of Cons cells ended with a nil | [
"List",
"creates",
"a",
"chain",
"of",
"Cons",
"cells",
"ended",
"with",
"a",
"nil"
] | 3bc9d9c574442c5f88a941e78f96cb57cb3fa357 | https://github.com/coyim/otr3/blob/3bc9d9c574442c5f88a941e78f96cb57cb3fa357/sexp/cons.go#L32-L41 |
13,801 | coyim/otr3 | sexp/cons.go | ReadList | func ReadList(r *bufio.Reader) Value {
ReadWhitespace(r)
if !ReadListStart(r) {
return nil
}
result := ReadListItem(r)
if !ReadListEnd(r) {
return nil
}
return result
} | go | func ReadList(r *bufio.Reader) Value {
ReadWhitespace(r)
if !ReadListStart(r) {
return nil
}
result := ReadListItem(r)
if !ReadListEnd(r) {
return nil
}
return result
} | [
"func",
"ReadList",
"(",
"r",
"*",
"bufio",
".",
"Reader",
")",
"Value",
"{",
"ReadWhitespace",
"(",
"r",
")",
"\n",
"if",
"!",
"ReadListStart",
"(",
"r",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"result",
":=",
"ReadListItem",
"(",
"r",
")",
"\n",
"if",
"!",
"ReadListEnd",
"(",
"r",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // ReadList will read a list and return it | [
"ReadList",
"will",
"read",
"a",
"list",
"and",
"return",
"it"
] | 3bc9d9c574442c5f88a941e78f96cb57cb3fa357 | https://github.com/coyim/otr3/blob/3bc9d9c574442c5f88a941e78f96cb57cb3fa357/sexp/cons.go#L54-L64 |
13,802 | coyim/otr3 | sexp/cons.go | ReadListItem | func ReadListItem(r *bufio.Reader) Value {
ReadWhitespace(r)
val, end := ReadValue(r)
if end {
return Snil{}
}
return Cons{val, ReadListItem(r)}
} | go | func ReadListItem(r *bufio.Reader) Value {
ReadWhitespace(r)
val, end := ReadValue(r)
if end {
return Snil{}
}
return Cons{val, ReadListItem(r)}
} | [
"func",
"ReadListItem",
"(",
"r",
"*",
"bufio",
".",
"Reader",
")",
"Value",
"{",
"ReadWhitespace",
"(",
"r",
")",
"\n",
"val",
",",
"end",
":=",
"ReadValue",
"(",
"r",
")",
"\n",
"if",
"end",
"{",
"return",
"Snil",
"{",
"}",
"\n",
"}",
"\n",
"return",
"Cons",
"{",
"val",
",",
"ReadListItem",
"(",
"r",
")",
"}",
"\n",
"}"
] | // ReadListItem recursively read a list item and the next potential item | [
"ReadListItem",
"recursively",
"read",
"a",
"list",
"item",
"and",
"the",
"next",
"potential",
"item"
] | 3bc9d9c574442c5f88a941e78f96cb57cb3fa357 | https://github.com/coyim/otr3/blob/3bc9d9c574442c5f88a941e78f96cb57cb3fa357/sexp/cons.go#L67-L74 |
13,803 | coyim/otr3 | ssid.go | SecureSessionID | func (c *Conversation) SecureSessionID() (parts []string, highlightIndex int) {
l := fmt.Sprintf("%0x", c.ssid[0:4])
r := fmt.Sprintf("%0x", c.ssid[4:])
ix := 1
if c.sentRevealSig {
ix = 0
}
return []string{l, r}, ix
} | go | func (c *Conversation) SecureSessionID() (parts []string, highlightIndex int) {
l := fmt.Sprintf("%0x", c.ssid[0:4])
r := fmt.Sprintf("%0x", c.ssid[4:])
ix := 1
if c.sentRevealSig {
ix = 0
}
return []string{l, r}, ix
} | [
"func",
"(",
"c",
"*",
"Conversation",
")",
"SecureSessionID",
"(",
")",
"(",
"parts",
"[",
"]",
"string",
",",
"highlightIndex",
"int",
")",
"{",
"l",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"c",
".",
"ssid",
"[",
"0",
":",
"4",
"]",
")",
"\n",
"r",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"c",
".",
"ssid",
"[",
"4",
":",
"]",
")",
"\n\n",
"ix",
":=",
"1",
"\n",
"if",
"c",
".",
"sentRevealSig",
"{",
"ix",
"=",
"0",
"\n",
"}",
"\n\n",
"return",
"[",
"]",
"string",
"{",
"l",
",",
"r",
"}",
",",
"ix",
"\n",
"}"
] | // SecureSessionID returns the secure session ID as two formatted strings
// The index returned points to the string that should be highlighted | [
"SecureSessionID",
"returns",
"the",
"secure",
"session",
"ID",
"as",
"two",
"formatted",
"strings",
"The",
"index",
"returned",
"points",
"to",
"the",
"string",
"that",
"should",
"be",
"highlighted"
] | 3bc9d9c574442c5f88a941e78f96cb57cb3fa357 | https://github.com/coyim/otr3/blob/3bc9d9c574442c5f88a941e78f96cb57cb3fa357/ssid.go#L7-L17 |
13,804 | coyim/otr3 | send.go | Send | func (c *Conversation) Send(m ValidMessage, trace ...interface{}) ([]ValidMessage, error) {
message := makeCopy(m)
defer wipeBytes(message)
if !c.Policies.isOTREnabled() {
return []ValidMessage{makeCopy(message)}, nil
}
if c.debug && bytes.Index(message, []byte(debugString)) != -1 {
c.dump(bufio.NewWriter(standardErrorOutput))
return nil, nil
}
switch c.msgState {
case plainText:
return c.withInjections(c.sendMessageOnPlaintext(message, trace...))
case encrypted:
return c.withInjections(c.sendMessageOnEncrypted(message))
case finished:
c.messageEvent(MessageEventConnectionEnded)
return c.withInjections(nil, newOtrError("cannot send message because secure conversation has finished"))
}
return c.withInjections(nil, newOtrError("cannot send message in current state"))
} | go | func (c *Conversation) Send(m ValidMessage, trace ...interface{}) ([]ValidMessage, error) {
message := makeCopy(m)
defer wipeBytes(message)
if !c.Policies.isOTREnabled() {
return []ValidMessage{makeCopy(message)}, nil
}
if c.debug && bytes.Index(message, []byte(debugString)) != -1 {
c.dump(bufio.NewWriter(standardErrorOutput))
return nil, nil
}
switch c.msgState {
case plainText:
return c.withInjections(c.sendMessageOnPlaintext(message, trace...))
case encrypted:
return c.withInjections(c.sendMessageOnEncrypted(message))
case finished:
c.messageEvent(MessageEventConnectionEnded)
return c.withInjections(nil, newOtrError("cannot send message because secure conversation has finished"))
}
return c.withInjections(nil, newOtrError("cannot send message in current state"))
} | [
"func",
"(",
"c",
"*",
"Conversation",
")",
"Send",
"(",
"m",
"ValidMessage",
",",
"trace",
"...",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"ValidMessage",
",",
"error",
")",
"{",
"message",
":=",
"makeCopy",
"(",
"m",
")",
"\n",
"defer",
"wipeBytes",
"(",
"message",
")",
"\n\n",
"if",
"!",
"c",
".",
"Policies",
".",
"isOTREnabled",
"(",
")",
"{",
"return",
"[",
"]",
"ValidMessage",
"{",
"makeCopy",
"(",
"message",
")",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"debug",
"&&",
"bytes",
".",
"Index",
"(",
"message",
",",
"[",
"]",
"byte",
"(",
"debugString",
")",
")",
"!=",
"-",
"1",
"{",
"c",
".",
"dump",
"(",
"bufio",
".",
"NewWriter",
"(",
"standardErrorOutput",
")",
")",
"\n",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"switch",
"c",
".",
"msgState",
"{",
"case",
"plainText",
":",
"return",
"c",
".",
"withInjections",
"(",
"c",
".",
"sendMessageOnPlaintext",
"(",
"message",
",",
"trace",
"...",
")",
")",
"\n",
"case",
"encrypted",
":",
"return",
"c",
".",
"withInjections",
"(",
"c",
".",
"sendMessageOnEncrypted",
"(",
"message",
")",
")",
"\n",
"case",
"finished",
":",
"c",
".",
"messageEvent",
"(",
"MessageEventConnectionEnded",
")",
"\n",
"return",
"c",
".",
"withInjections",
"(",
"nil",
",",
"newOtrError",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"withInjections",
"(",
"nil",
",",
"newOtrError",
"(",
"\"",
"\"",
")",
")",
"\n",
"}"
] | // Send takes a human readable message from the local user, possibly encrypts
// it and returns zero or more messages to send to the peer. | [
"Send",
"takes",
"a",
"human",
"readable",
"message",
"from",
"the",
"local",
"user",
"possibly",
"encrypts",
"it",
"and",
"returns",
"zero",
"or",
"more",
"messages",
"to",
"send",
"to",
"the",
"peer",
"."
] | 3bc9d9c574442c5f88a941e78f96cb57cb3fa357 | https://github.com/coyim/otr3/blob/3bc9d9c574442c5f88a941e78f96cb57cb3fa357/send.go#L10-L34 |
13,805 | coyim/otr3 | sexp/str.go | ReadString | func ReadString(r *bufio.Reader) Value {
ReadWhitespace(r)
if !ReadStringStart(r) {
return nil
}
result := ReadDataUntil(r, untilFixed('"'))
if !ReadStringEnd(r) {
return nil
}
return Sstring(result)
} | go | func ReadString(r *bufio.Reader) Value {
ReadWhitespace(r)
if !ReadStringStart(r) {
return nil
}
result := ReadDataUntil(r, untilFixed('"'))
if !ReadStringEnd(r) {
return nil
}
return Sstring(result)
} | [
"func",
"ReadString",
"(",
"r",
"*",
"bufio",
".",
"Reader",
")",
"Value",
"{",
"ReadWhitespace",
"(",
"r",
")",
"\n",
"if",
"!",
"ReadStringStart",
"(",
"r",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"result",
":=",
"ReadDataUntil",
"(",
"r",
",",
"untilFixed",
"(",
"'\"'",
")",
")",
"\n",
"if",
"!",
"ReadStringEnd",
"(",
"r",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"Sstring",
"(",
"result",
")",
"\n",
"}"
] | // ReadString will read a string from the reader | [
"ReadString",
"will",
"read",
"a",
"string",
"from",
"the",
"reader"
] | 3bc9d9c574442c5f88a941e78f96cb57cb3fa357 | https://github.com/coyim/otr3/blob/3bc9d9c574442c5f88a941e78f96cb57cb3fa357/sexp/str.go#L39-L49 |
13,806 | coyim/otr3 | error_codes.go | HandleErrorMessage | func (DebugErrorMessageHandler) HandleErrorMessage(error ErrorCode) []byte {
fmt.Fprintf(standardErrorOutput, "%sHandleErrorMessage(%s)\n", debugPrefix, error)
return nil
} | go | func (DebugErrorMessageHandler) HandleErrorMessage(error ErrorCode) []byte {
fmt.Fprintf(standardErrorOutput, "%sHandleErrorMessage(%s)\n", debugPrefix, error)
return nil
} | [
"func",
"(",
"DebugErrorMessageHandler",
")",
"HandleErrorMessage",
"(",
"error",
"ErrorCode",
")",
"[",
"]",
"byte",
"{",
"fmt",
".",
"Fprintf",
"(",
"standardErrorOutput",
",",
"\"",
"\\n",
"\"",
",",
"debugPrefix",
",",
"error",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // HandleErrorMessage dumps all error messages and returns nil | [
"HandleErrorMessage",
"dumps",
"all",
"error",
"messages",
"and",
"returns",
"nil"
] | 3bc9d9c574442c5f88a941e78f96cb57cb3fa357 | https://github.com/coyim/otr3/blob/3bc9d9c574442c5f88a941e78f96cb57cb3fa357/error_codes.go#L82-L85 |
13,807 | coyim/otr3 | smp.go | SMPQuestion | func (c *Conversation) SMPQuestion() (string, bool) {
if c.smp.question == nil {
return "", false
}
return *c.smp.question, true
} | go | func (c *Conversation) SMPQuestion() (string, bool) {
if c.smp.question == nil {
return "", false
}
return *c.smp.question, true
} | [
"func",
"(",
"c",
"*",
"Conversation",
")",
"SMPQuestion",
"(",
")",
"(",
"string",
",",
"bool",
")",
"{",
"if",
"c",
".",
"smp",
".",
"question",
"==",
"nil",
"{",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}",
"\n",
"return",
"*",
"c",
".",
"smp",
".",
"question",
",",
"true",
"\n",
"}"
] | // SMPQuestion returns the current SMP question and ok if there is one, and not ok if there isn't one. | [
"SMPQuestion",
"returns",
"the",
"current",
"SMP",
"question",
"and",
"ok",
"if",
"there",
"is",
"one",
"and",
"not",
"ok",
"if",
"there",
"isn",
"t",
"one",
"."
] | 3bc9d9c574442c5f88a941e78f96cb57cb3fa357 | https://github.com/coyim/otr3/blob/3bc9d9c574442c5f88a941e78f96cb57cb3fa357/smp.go#L39-L44 |
13,808 | coyim/otr3 | authenticate.go | StartAuthenticate | func (c *Conversation) StartAuthenticate(question string, mutualSecret []byte) ([]ValidMessage, error) {
c.smp.ensureSMP()
tlvs, err := c.smp.state.startAuthenticate(c, question, mutualSecret)
if err != nil {
return nil, err
}
msgs, _, err := c.createSerializedDataMessage(nil, messageFlagIgnoreUnreadable, tlvs)
return msgs, err
} | go | func (c *Conversation) StartAuthenticate(question string, mutualSecret []byte) ([]ValidMessage, error) {
c.smp.ensureSMP()
tlvs, err := c.smp.state.startAuthenticate(c, question, mutualSecret)
if err != nil {
return nil, err
}
msgs, _, err := c.createSerializedDataMessage(nil, messageFlagIgnoreUnreadable, tlvs)
return msgs, err
} | [
"func",
"(",
"c",
"*",
"Conversation",
")",
"StartAuthenticate",
"(",
"question",
"string",
",",
"mutualSecret",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"ValidMessage",
",",
"error",
")",
"{",
"c",
".",
"smp",
".",
"ensureSMP",
"(",
")",
"\n\n",
"tlvs",
",",
"err",
":=",
"c",
".",
"smp",
".",
"state",
".",
"startAuthenticate",
"(",
"c",
",",
"question",
",",
"mutualSecret",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"msgs",
",",
"_",
",",
"err",
":=",
"c",
".",
"createSerializedDataMessage",
"(",
"nil",
",",
"messageFlagIgnoreUnreadable",
",",
"tlvs",
")",
"\n",
"return",
"msgs",
",",
"err",
"\n",
"}"
] | // StartAuthenticate should be called when the user wants to initiate authentication with a peer.
// The authentication uses an optional question message and a shared secret. The authentication will proceed
// until the event handler reports that SMP is complete, that a secret is needed or that SMP has failed. | [
"StartAuthenticate",
"should",
"be",
"called",
"when",
"the",
"user",
"wants",
"to",
"initiate",
"authentication",
"with",
"a",
"peer",
".",
"The",
"authentication",
"uses",
"an",
"optional",
"question",
"message",
"and",
"a",
"shared",
"secret",
".",
"The",
"authentication",
"will",
"proceed",
"until",
"the",
"event",
"handler",
"reports",
"that",
"SMP",
"is",
"complete",
"that",
"a",
"secret",
"is",
"needed",
"or",
"that",
"SMP",
"has",
"failed",
"."
] | 3bc9d9c574442c5f88a941e78f96cb57cb3fa357 | https://github.com/coyim/otr3/blob/3bc9d9c574442c5f88a941e78f96cb57cb3fa357/authenticate.go#L6-L17 |
13,809 | coyim/otr3 | authenticate.go | ProvideAuthenticationSecret | func (c *Conversation) ProvideAuthenticationSecret(mutualSecret []byte) ([]ValidMessage, error) {
t, err := c.continueSMP(mutualSecret)
if err != nil {
return nil, err
}
msgs, _, err := c.createSerializedDataMessage(nil, messageFlagIgnoreUnreadable, []tlv{*t})
return msgs, err
} | go | func (c *Conversation) ProvideAuthenticationSecret(mutualSecret []byte) ([]ValidMessage, error) {
t, err := c.continueSMP(mutualSecret)
if err != nil {
return nil, err
}
msgs, _, err := c.createSerializedDataMessage(nil, messageFlagIgnoreUnreadable, []tlv{*t})
return msgs, err
} | [
"func",
"(",
"c",
"*",
"Conversation",
")",
"ProvideAuthenticationSecret",
"(",
"mutualSecret",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"ValidMessage",
",",
"error",
")",
"{",
"t",
",",
"err",
":=",
"c",
".",
"continueSMP",
"(",
"mutualSecret",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"msgs",
",",
"_",
",",
"err",
":=",
"c",
".",
"createSerializedDataMessage",
"(",
"nil",
",",
"messageFlagIgnoreUnreadable",
",",
"[",
"]",
"tlv",
"{",
"*",
"t",
"}",
")",
"\n",
"return",
"msgs",
",",
"err",
"\n",
"}"
] | // ProvideAuthenticationSecret should be called when the peer has started an authentication request, and the UI has been notified that a secret is needed
// It is only valid to call this function if the current SMP state is waiting for a secret to be provided. The return is the potential messages to send. | [
"ProvideAuthenticationSecret",
"should",
"be",
"called",
"when",
"the",
"peer",
"has",
"started",
"an",
"authentication",
"request",
"and",
"the",
"UI",
"has",
"been",
"notified",
"that",
"a",
"secret",
"is",
"needed",
"It",
"is",
"only",
"valid",
"to",
"call",
"this",
"function",
"if",
"the",
"current",
"SMP",
"state",
"is",
"waiting",
"for",
"a",
"secret",
"to",
"be",
"provided",
".",
"The",
"return",
"is",
"the",
"potential",
"messages",
"to",
"send",
"."
] | 3bc9d9c574442c5f88a941e78f96cb57cb3fa357 | https://github.com/coyim/otr3/blob/3bc9d9c574442c5f88a941e78f96cb57cb3fa357/authenticate.go#L21-L29 |
13,810 | coyim/otr3 | authenticate.go | AbortAuthentication | func (c *Conversation) AbortAuthentication() ([]ValidMessage, error) {
t := c.restartSMP()
msgs, _, err := c.createSerializedDataMessage(nil, messageFlagIgnoreUnreadable, []tlv{t})
return msgs, err
} | go | func (c *Conversation) AbortAuthentication() ([]ValidMessage, error) {
t := c.restartSMP()
msgs, _, err := c.createSerializedDataMessage(nil, messageFlagIgnoreUnreadable, []tlv{t})
return msgs, err
} | [
"func",
"(",
"c",
"*",
"Conversation",
")",
"AbortAuthentication",
"(",
")",
"(",
"[",
"]",
"ValidMessage",
",",
"error",
")",
"{",
"t",
":=",
"c",
".",
"restartSMP",
"(",
")",
"\n\n",
"msgs",
",",
"_",
",",
"err",
":=",
"c",
".",
"createSerializedDataMessage",
"(",
"nil",
",",
"messageFlagIgnoreUnreadable",
",",
"[",
"]",
"tlv",
"{",
"t",
"}",
")",
"\n",
"return",
"msgs",
",",
"err",
"\n",
"}"
] | // AbortAuthentication should be called when the user wants to abort authentication with a peer.
// It will return an SMP abort message to send. | [
"AbortAuthentication",
"should",
"be",
"called",
"when",
"the",
"user",
"wants",
"to",
"abort",
"authentication",
"with",
"a",
"peer",
".",
"It",
"will",
"return",
"an",
"SMP",
"abort",
"message",
"to",
"send",
"."
] | 3bc9d9c574442c5f88a941e78f96cb57cb3fa357 | https://github.com/coyim/otr3/blob/3bc9d9c574442c5f88a941e78f96cb57cb3fa357/authenticate.go#L33-L38 |
13,811 | coyim/otr3 | conversation.go | NewConversationWithVersion | func NewConversationWithVersion(v int) *Conversation {
var vv otrVersion
switch v {
case 2:
vv = otrV2{}
case 3:
vv = otrV3{}
}
return &Conversation{version: vv}
} | go | func NewConversationWithVersion(v int) *Conversation {
var vv otrVersion
switch v {
case 2:
vv = otrV2{}
case 3:
vv = otrV3{}
}
return &Conversation{version: vv}
} | [
"func",
"NewConversationWithVersion",
"(",
"v",
"int",
")",
"*",
"Conversation",
"{",
"var",
"vv",
"otrVersion",
"\n\n",
"switch",
"v",
"{",
"case",
"2",
":",
"vv",
"=",
"otrV2",
"{",
"}",
"\n",
"case",
"3",
":",
"vv",
"=",
"otrV3",
"{",
"}",
"\n",
"}",
"\n",
"return",
"&",
"Conversation",
"{",
"version",
":",
"vv",
"}",
"\n",
"}"
] | // NewConversationWithVersion creates a new conversation with the given version | [
"NewConversationWithVersion",
"creates",
"a",
"new",
"conversation",
"with",
"the",
"given",
"version"
] | 3bc9d9c574442c5f88a941e78f96cb57cb3fa357 | https://github.com/coyim/otr3/blob/3bc9d9c574442c5f88a941e78f96cb57cb3fa357/conversation.go#L65-L75 |
13,812 | coyim/otr3 | conversation.go | End | func (c *Conversation) End() (toSend []ValidMessage, err error) {
previousMsgState := c.msgState
if c.msgState == encrypted {
c.smp.wipe()
// Error can only happen when Rand reader is broken
toSend, _, err = c.createSerializedDataMessage(nil, messageFlagIgnoreUnreadable, []tlv{tlv{tlvType: tlvTypeDisconnected}})
}
c.lastMessageStateChange = time.Time{}
c.ake = nil
c.msgState = plainText
defer c.signalSecurityEventIf(previousMsgState == encrypted, GoneInsecure)
c.keys.ourCurrentDHKeys.wipe()
c.keys.ourPreviousDHKeys.wipe()
wipeBigInt(c.keys.theirCurrentDHPubKey)
return
} | go | func (c *Conversation) End() (toSend []ValidMessage, err error) {
previousMsgState := c.msgState
if c.msgState == encrypted {
c.smp.wipe()
// Error can only happen when Rand reader is broken
toSend, _, err = c.createSerializedDataMessage(nil, messageFlagIgnoreUnreadable, []tlv{tlv{tlvType: tlvTypeDisconnected}})
}
c.lastMessageStateChange = time.Time{}
c.ake = nil
c.msgState = plainText
defer c.signalSecurityEventIf(previousMsgState == encrypted, GoneInsecure)
c.keys.ourCurrentDHKeys.wipe()
c.keys.ourPreviousDHKeys.wipe()
wipeBigInt(c.keys.theirCurrentDHPubKey)
return
} | [
"func",
"(",
"c",
"*",
"Conversation",
")",
"End",
"(",
")",
"(",
"toSend",
"[",
"]",
"ValidMessage",
",",
"err",
"error",
")",
"{",
"previousMsgState",
":=",
"c",
".",
"msgState",
"\n",
"if",
"c",
".",
"msgState",
"==",
"encrypted",
"{",
"c",
".",
"smp",
".",
"wipe",
"(",
")",
"\n",
"// Error can only happen when Rand reader is broken",
"toSend",
",",
"_",
",",
"err",
"=",
"c",
".",
"createSerializedDataMessage",
"(",
"nil",
",",
"messageFlagIgnoreUnreadable",
",",
"[",
"]",
"tlv",
"{",
"tlv",
"{",
"tlvType",
":",
"tlvTypeDisconnected",
"}",
"}",
")",
"\n",
"}",
"\n",
"c",
".",
"lastMessageStateChange",
"=",
"time",
".",
"Time",
"{",
"}",
"\n",
"c",
".",
"ake",
"=",
"nil",
"\n",
"c",
".",
"msgState",
"=",
"plainText",
"\n",
"defer",
"c",
".",
"signalSecurityEventIf",
"(",
"previousMsgState",
"==",
"encrypted",
",",
"GoneInsecure",
")",
"\n\n",
"c",
".",
"keys",
".",
"ourCurrentDHKeys",
".",
"wipe",
"(",
")",
"\n",
"c",
".",
"keys",
".",
"ourPreviousDHKeys",
".",
"wipe",
"(",
")",
"\n",
"wipeBigInt",
"(",
"c",
".",
"keys",
".",
"theirCurrentDHPubKey",
")",
"\n",
"return",
"\n",
"}"
] | // End ends a secure conversation by generating a termination message for
// the peer and switches to unencrypted communication. | [
"End",
"ends",
"a",
"secure",
"conversation",
"by",
"generating",
"a",
"termination",
"message",
"for",
"the",
"peer",
"and",
"switches",
"to",
"unencrypted",
"communication",
"."
] | 3bc9d9c574442c5f88a941e78f96cb57cb3fa357 | https://github.com/coyim/otr3/blob/3bc9d9c574442c5f88a941e78f96cb57cb3fa357/conversation.go#L114-L130 |
13,813 | coyim/otr3 | conversation.go | InitializeInstanceTag | func (c *Conversation) InitializeInstanceTag(tag uint32) uint32 {
if tag == 0 {
c.generateInstanceTag()
} else {
c.ourInstanceTag = tag
}
return c.ourInstanceTag
} | go | func (c *Conversation) InitializeInstanceTag(tag uint32) uint32 {
if tag == 0 {
c.generateInstanceTag()
} else {
c.ourInstanceTag = tag
}
return c.ourInstanceTag
} | [
"func",
"(",
"c",
"*",
"Conversation",
")",
"InitializeInstanceTag",
"(",
"tag",
"uint32",
")",
"uint32",
"{",
"if",
"tag",
"==",
"0",
"{",
"c",
".",
"generateInstanceTag",
"(",
")",
"\n",
"}",
"else",
"{",
"c",
".",
"ourInstanceTag",
"=",
"tag",
"\n",
"}",
"\n",
"return",
"c",
".",
"ourInstanceTag",
"\n",
"}"
] | // InitializeInstanceTag sets our instance tag for this conversation. If the argument is zero we will create a new instance tag and return it
// The instance tag created or set will be returned | [
"InitializeInstanceTag",
"sets",
"our",
"instance",
"tag",
"for",
"this",
"conversation",
".",
"If",
"the",
"argument",
"is",
"zero",
"we",
"will",
"create",
"a",
"new",
"instance",
"tag",
"and",
"return",
"it",
"The",
"instance",
"tag",
"created",
"or",
"set",
"will",
"be",
"returned"
] | 3bc9d9c574442c5f88a941e78f96cb57cb3fa357 | https://github.com/coyim/otr3/blob/3bc9d9c574442c5f88a941e78f96cb57cb3fa357/conversation.go#L179-L186 |
13,814 | coyim/otr3 | sexp/bignum.go | NewBigNum | func NewBigNum(s string) BigNum {
res, _ := new(big.Int).SetString(s, 16)
return BigNum{res}
} | go | func NewBigNum(s string) BigNum {
res, _ := new(big.Int).SetString(s, 16)
return BigNum{res}
} | [
"func",
"NewBigNum",
"(",
"s",
"string",
")",
"BigNum",
"{",
"res",
",",
"_",
":=",
"new",
"(",
"big",
".",
"Int",
")",
".",
"SetString",
"(",
"s",
",",
"16",
")",
"\n",
"return",
"BigNum",
"{",
"res",
"}",
"\n",
"}"
] | // NewBigNum creates a new BigNum from the hex formatted string given | [
"NewBigNum",
"creates",
"a",
"new",
"BigNum",
"from",
"the",
"hex",
"formatted",
"string",
"given"
] | 3bc9d9c574442c5f88a941e78f96cb57cb3fa357 | https://github.com/coyim/otr3/blob/3bc9d9c574442c5f88a941e78f96cb57cb3fa357/sexp/bignum.go#L15-L18 |
13,815 | coyim/otr3 | sexp/bignum.go | ReadBigNum | func ReadBigNum(r *bufio.Reader) Value {
ReadWhitespace(r)
if !ReadBigNumStart(r) {
return nil
}
result := ReadDataUntil(r, untilFixed('#'))
if !ReadBigNumEnd(r) {
return nil
}
return NewBigNum(string(result))
} | go | func ReadBigNum(r *bufio.Reader) Value {
ReadWhitespace(r)
if !ReadBigNumStart(r) {
return nil
}
result := ReadDataUntil(r, untilFixed('#'))
if !ReadBigNumEnd(r) {
return nil
}
return NewBigNum(string(result))
} | [
"func",
"ReadBigNum",
"(",
"r",
"*",
"bufio",
".",
"Reader",
")",
"Value",
"{",
"ReadWhitespace",
"(",
"r",
")",
"\n",
"if",
"!",
"ReadBigNumStart",
"(",
"r",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"result",
":=",
"ReadDataUntil",
"(",
"r",
",",
"untilFixed",
"(",
"'#'",
")",
")",
"\n",
"if",
"!",
"ReadBigNumEnd",
"(",
"r",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"NewBigNum",
"(",
"string",
"(",
"result",
")",
")",
"\n",
"}"
] | // ReadBigNum will read a bignum from the given reader and return it | [
"ReadBigNum",
"will",
"read",
"a",
"bignum",
"from",
"the",
"given",
"reader",
"and",
"return",
"it"
] | 3bc9d9c574442c5f88a941e78f96cb57cb3fa357 | https://github.com/coyim/otr3/blob/3bc9d9c574442c5f88a941e78f96cb57cb3fa357/sexp/bignum.go#L51-L61 |
13,816 | coyim/otr3 | sexp/sexp.go | Read | func Read(r *bufio.Reader) Value {
res, _ := ReadValue(r)
return res
} | go | func Read(r *bufio.Reader) Value {
res, _ := ReadValue(r)
return res
} | [
"func",
"Read",
"(",
"r",
"*",
"bufio",
".",
"Reader",
")",
"Value",
"{",
"res",
",",
"_",
":=",
"ReadValue",
"(",
"r",
")",
"\n",
"return",
"res",
"\n",
"}"
] | // Read will read an S-Expression from the given reader | [
"Read",
"will",
"read",
"an",
"S",
"-",
"Expression",
"from",
"the",
"given",
"reader"
] | 3bc9d9c574442c5f88a941e78f96cb57cb3fa357 | https://github.com/coyim/otr3/blob/3bc9d9c574442c5f88a941e78f96cb57cb3fa357/sexp/sexp.go#L25-L28 |
13,817 | coyim/otr3 | sexp/sexp.go | ReadWhitespace | func ReadWhitespace(r *bufio.Reader) {
c, e := peek(r)
for e != io.EOF && isWhitespace(c) {
r.ReadByte()
c, e = peek(r)
}
} | go | func ReadWhitespace(r *bufio.Reader) {
c, e := peek(r)
for e != io.EOF && isWhitespace(c) {
r.ReadByte()
c, e = peek(r)
}
} | [
"func",
"ReadWhitespace",
"(",
"r",
"*",
"bufio",
".",
"Reader",
")",
"{",
"c",
",",
"e",
":=",
"peek",
"(",
"r",
")",
"\n",
"for",
"e",
"!=",
"io",
".",
"EOF",
"&&",
"isWhitespace",
"(",
"c",
")",
"{",
"r",
".",
"ReadByte",
"(",
")",
"\n",
"c",
",",
"e",
"=",
"peek",
"(",
"r",
")",
"\n",
"}",
"\n",
"}"
] | // ReadWhitespace will read from the reader until no whitespace is encountered | [
"ReadWhitespace",
"will",
"read",
"from",
"the",
"reader",
"until",
"no",
"whitespace",
"is",
"encountered"
] | 3bc9d9c574442c5f88a941e78f96cb57cb3fa357 | https://github.com/coyim/otr3/blob/3bc9d9c574442c5f88a941e78f96cb57cb3fa357/sexp/sexp.go#L31-L37 |
13,818 | coyim/otr3 | sexp/sexp.go | ReadValue | func ReadValue(r *bufio.Reader) (Value, bool) {
ReadWhitespace(r)
c, err := peek(r)
if err != nil {
return nil, true
}
switch c {
case '(':
return ReadList(r), false
case ')':
return nil, true
case '"':
return ReadString(r), false
case '#':
return ReadBigNum(r), false
default:
return ReadSymbol(r), false
}
} | go | func ReadValue(r *bufio.Reader) (Value, bool) {
ReadWhitespace(r)
c, err := peek(r)
if err != nil {
return nil, true
}
switch c {
case '(':
return ReadList(r), false
case ')':
return nil, true
case '"':
return ReadString(r), false
case '#':
return ReadBigNum(r), false
default:
return ReadSymbol(r), false
}
} | [
"func",
"ReadValue",
"(",
"r",
"*",
"bufio",
".",
"Reader",
")",
"(",
"Value",
",",
"bool",
")",
"{",
"ReadWhitespace",
"(",
"r",
")",
"\n",
"c",
",",
"err",
":=",
"peek",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"true",
"\n",
"}",
"\n",
"switch",
"c",
"{",
"case",
"'('",
":",
"return",
"ReadList",
"(",
"r",
")",
",",
"false",
"\n",
"case",
"')'",
":",
"return",
"nil",
",",
"true",
"\n",
"case",
"'\"'",
":",
"return",
"ReadString",
"(",
"r",
")",
",",
"false",
"\n",
"case",
"'#'",
":",
"return",
"ReadBigNum",
"(",
"r",
")",
",",
"false",
"\n",
"default",
":",
"return",
"ReadSymbol",
"(",
"r",
")",
",",
"false",
"\n",
"}",
"\n",
"}"
] | // ReadValue will read and return an S-Expression value from the reader | [
"ReadValue",
"will",
"read",
"and",
"return",
"an",
"S",
"-",
"Expression",
"value",
"from",
"the",
"reader"
] | 3bc9d9c574442c5f88a941e78f96cb57cb3fa357 | https://github.com/coyim/otr3/blob/3bc9d9c574442c5f88a941e78f96cb57cb3fa357/sexp/sexp.go#L40-L58 |
13,819 | coyim/otr3 | sexp/sexp.go | ReadDataUntil | func ReadDataUntil(r *bufio.Reader, until func(byte) bool) []byte {
result := make([]byte, 0, 10)
c, err := peek(r)
for err != io.EOF && !until(c) {
r.ReadByte()
result = append(result, c)
c, err = peek(r)
}
return result
} | go | func ReadDataUntil(r *bufio.Reader, until func(byte) bool) []byte {
result := make([]byte, 0, 10)
c, err := peek(r)
for err != io.EOF && !until(c) {
r.ReadByte()
result = append(result, c)
c, err = peek(r)
}
return result
} | [
"func",
"ReadDataUntil",
"(",
"r",
"*",
"bufio",
".",
"Reader",
",",
"until",
"func",
"(",
"byte",
")",
"bool",
")",
"[",
"]",
"byte",
"{",
"result",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"10",
")",
"\n",
"c",
",",
"err",
":=",
"peek",
"(",
"r",
")",
"\n",
"for",
"err",
"!=",
"io",
".",
"EOF",
"&&",
"!",
"until",
"(",
"c",
")",
"{",
"r",
".",
"ReadByte",
"(",
")",
"\n",
"result",
"=",
"append",
"(",
"result",
",",
"c",
")",
"\n",
"c",
",",
"err",
"=",
"peek",
"(",
"r",
")",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // ReadDataUntil will read and collect bytes from the reader until it encounters EOF or the given function returns true. | [
"ReadDataUntil",
"will",
"read",
"and",
"collect",
"bytes",
"from",
"the",
"reader",
"until",
"it",
"encounters",
"EOF",
"or",
"the",
"given",
"function",
"returns",
"true",
"."
] | 3bc9d9c574442c5f88a941e78f96cb57cb3fa357 | https://github.com/coyim/otr3/blob/3bc9d9c574442c5f88a941e78f96cb57cb3fa357/sexp/sexp.go#L98-L107 |
13,820 | containous/traefik-extra-service-fabric | servicefabric.go | Provide | func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *safe.Pool) error {
return p.updateConfig(configurationChan, pool, time.Duration(p.RefreshSeconds))
} | go | func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *safe.Pool) error {
return p.updateConfig(configurationChan, pool, time.Duration(p.RefreshSeconds))
} | [
"func",
"(",
"p",
"*",
"Provider",
")",
"Provide",
"(",
"configurationChan",
"chan",
"<-",
"types",
".",
"ConfigMessage",
",",
"pool",
"*",
"safe",
".",
"Pool",
")",
"error",
"{",
"return",
"p",
".",
"updateConfig",
"(",
"configurationChan",
",",
"pool",
",",
"time",
".",
"Duration",
"(",
"p",
".",
"RefreshSeconds",
")",
")",
"\n",
"}"
] | // Provide allows the ServiceFabric provider to provide configurations to traefik
// using the given configuration channel. | [
"Provide",
"allows",
"the",
"ServiceFabric",
"provider",
"to",
"provide",
"configurations",
"to",
"traefik",
"using",
"the",
"given",
"configuration",
"channel",
"."
] | f9f49c0a6d51a8205faf34dd3cb7d628611257e5 | https://github.com/containous/traefik-extra-service-fabric/blob/f9f49c0a6d51a8205faf34dd3cb7d628611257e5/servicefabric.go#L84-L86 |
13,821 | containous/traefik-extra-service-fabric | servicefabric.go | getLabels | func getLabels(sfClient sfClient, service *sf.ServiceItem, app *sf.ApplicationItem) (map[string]string, error) {
labels, err := sfClient.GetServiceExtensionMap(service, app, traefikServiceFabricExtensionKey)
if err != nil {
log.Errorf("Error retrieving serviceExtensionMap: %v", err)
return nil, err
}
if label.GetBoolValue(labels, traefikSFEnableLabelOverrides, traefikSFEnableLabelOverridesDefault) {
if exists, properties, err := sfClient.GetProperties(service.ID); err == nil && exists {
for key, value := range properties {
labels[key] = value
}
}
}
return labels, nil
} | go | func getLabels(sfClient sfClient, service *sf.ServiceItem, app *sf.ApplicationItem) (map[string]string, error) {
labels, err := sfClient.GetServiceExtensionMap(service, app, traefikServiceFabricExtensionKey)
if err != nil {
log.Errorf("Error retrieving serviceExtensionMap: %v", err)
return nil, err
}
if label.GetBoolValue(labels, traefikSFEnableLabelOverrides, traefikSFEnableLabelOverridesDefault) {
if exists, properties, err := sfClient.GetProperties(service.ID); err == nil && exists {
for key, value := range properties {
labels[key] = value
}
}
}
return labels, nil
} | [
"func",
"getLabels",
"(",
"sfClient",
"sfClient",
",",
"service",
"*",
"sf",
".",
"ServiceItem",
",",
"app",
"*",
"sf",
".",
"ApplicationItem",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"labels",
",",
"err",
":=",
"sfClient",
".",
"GetServiceExtensionMap",
"(",
"service",
",",
"app",
",",
"traefikServiceFabricExtensionKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"label",
".",
"GetBoolValue",
"(",
"labels",
",",
"traefikSFEnableLabelOverrides",
",",
"traefikSFEnableLabelOverridesDefault",
")",
"{",
"if",
"exists",
",",
"properties",
",",
"err",
":=",
"sfClient",
".",
"GetProperties",
"(",
"service",
".",
"ID",
")",
";",
"err",
"==",
"nil",
"&&",
"exists",
"{",
"for",
"key",
",",
"value",
":=",
"range",
"properties",
"{",
"labels",
"[",
"key",
"]",
"=",
"value",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"labels",
",",
"nil",
"\n",
"}"
] | // Return a set of labels from the Extension and Property manager
// Allow Extension labels to disable importing labels from the property manager. | [
"Return",
"a",
"set",
"of",
"labels",
"from",
"the",
"Extension",
"and",
"Property",
"manager",
"Allow",
"Extension",
"labels",
"to",
"disable",
"importing",
"labels",
"from",
"the",
"property",
"manager",
"."
] | f9f49c0a6d51a8205faf34dd3cb7d628611257e5 | https://github.com/containous/traefik-extra-service-fabric/blob/f9f49c0a6d51a8205faf34dd3cb7d628611257e5/servicefabric.go#L277-L292 |
13,822 | itsyouonline/identityserver | identityservice/user/client_id_middleware.go | newClientIDMiddleware | func newClientIDMiddleware(scopes []string) *ClientIDMiddleware {
om := ClientIDMiddleware{}
om.Scopes = scopes
return &om
} | go | func newClientIDMiddleware(scopes []string) *ClientIDMiddleware {
om := ClientIDMiddleware{}
om.Scopes = scopes
return &om
} | [
"func",
"newClientIDMiddleware",
"(",
"scopes",
"[",
"]",
"string",
")",
"*",
"ClientIDMiddleware",
"{",
"om",
":=",
"ClientIDMiddleware",
"{",
"}",
"\n",
"om",
".",
"Scopes",
"=",
"scopes",
"\n",
"return",
"&",
"om",
"\n",
"}"
] | // newClientIDMiddlware new ClientIDMiddlware struct | [
"newClientIDMiddlware",
"new",
"ClientIDMiddlware",
"struct"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/user/client_id_middleware.go#L19-L23 |
13,823 | itsyouonline/identityserver | identityservice/security/oauth2.go | GetAccessToken | func (om *OAuth2Middleware) GetAccessToken(r *http.Request) string {
authorizationHeader := r.Header.Get("Authorization")
if authorizationHeader == "" {
accessTokenQueryParameter := r.URL.Query().Get("access_token")
return accessTokenQueryParameter
}
if strings.HasPrefix(authorizationHeader, "bearer ") || strings.HasPrefix(authorizationHeader, "Bearer ") {
return ""
}
accessToken := strings.TrimSpace(strings.TrimPrefix(authorizationHeader, "token"))
return accessToken
} | go | func (om *OAuth2Middleware) GetAccessToken(r *http.Request) string {
authorizationHeader := r.Header.Get("Authorization")
if authorizationHeader == "" {
accessTokenQueryParameter := r.URL.Query().Get("access_token")
return accessTokenQueryParameter
}
if strings.HasPrefix(authorizationHeader, "bearer ") || strings.HasPrefix(authorizationHeader, "Bearer ") {
return ""
}
accessToken := strings.TrimSpace(strings.TrimPrefix(authorizationHeader, "token"))
return accessToken
} | [
"func",
"(",
"om",
"*",
"OAuth2Middleware",
")",
"GetAccessToken",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"string",
"{",
"authorizationHeader",
":=",
"r",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n\n",
"if",
"authorizationHeader",
"==",
"\"",
"\"",
"{",
"accessTokenQueryParameter",
":=",
"r",
".",
"URL",
".",
"Query",
"(",
")",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"return",
"accessTokenQueryParameter",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"authorizationHeader",
",",
"\"",
"\"",
")",
"||",
"strings",
".",
"HasPrefix",
"(",
"authorizationHeader",
",",
"\"",
"\"",
")",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"accessToken",
":=",
"strings",
".",
"TrimSpace",
"(",
"strings",
".",
"TrimPrefix",
"(",
"authorizationHeader",
",",
"\"",
"\"",
")",
")",
"\n",
"return",
"accessToken",
"\n",
"}"
] | //GetAccessToken returns the access token from the authorization header or from the query parameters.
// If the authorization header starts with "bearer", "" is returned | [
"GetAccessToken",
"returns",
"the",
"access",
"token",
"from",
"the",
"authorization",
"header",
"or",
"from",
"the",
"query",
"parameters",
".",
"If",
"the",
"authorization",
"header",
"starts",
"with",
"bearer",
"is",
"returned"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/security/oauth2.go#L19-L32 |
13,824 | itsyouonline/identityserver | identityservice/organization/organizations_api.go | autoAcceptSubOrgInvite | func (api OrganizationsAPI) autoAcceptSubOrgInvite(invite *invitations.JoinOrganizationInvitation, mgr *organization.Manager) (bool, error) {
globalid := invite.Organization
// If this is an invite for a root organization we obviously aren't a member of a parent yet
if !strings.Contains(globalid, ".") {
return false, nil
}
// Check for username so we only auto accept already registered users
// Not sure if this is needed but it doesn't hurt to check
username := invite.User
if username == "" {
log.Debug("can't auto accept the invite because the username is not known")
return false, nil
}
// Check if we happen to be a member or owner of a parent org
orgs, err := mgr.AllByUser(username)
if err != nil {
return false, err
}
inParent := false
for _, org := range orgs {
// adding the "." is required here.
if strings.HasPrefix(globalid, org.Globalid+".") {
inParent = true
break
}
}
if !inParent {
return false, nil
}
// add the user
org, err := mgr.GetByName(invite.Organization)
if err != nil {
return false, err
}
if invitations.RoleOwner == invite.Role {
// Accepted Owner role
if err := mgr.SaveOwner(org, username); err != nil {
return false, err
}
} else {
// Accepted member role
if err := mgr.SaveMember(org, username); err != nil {
return false, err
}
}
// set the invite to status accpeted
invite.Status = invitations.RequestAccepted
log.Debug("Invitation auto accepted because the user is already an owner or member of a parent organization")
return true, nil
} | go | func (api OrganizationsAPI) autoAcceptSubOrgInvite(invite *invitations.JoinOrganizationInvitation, mgr *organization.Manager) (bool, error) {
globalid := invite.Organization
// If this is an invite for a root organization we obviously aren't a member of a parent yet
if !strings.Contains(globalid, ".") {
return false, nil
}
// Check for username so we only auto accept already registered users
// Not sure if this is needed but it doesn't hurt to check
username := invite.User
if username == "" {
log.Debug("can't auto accept the invite because the username is not known")
return false, nil
}
// Check if we happen to be a member or owner of a parent org
orgs, err := mgr.AllByUser(username)
if err != nil {
return false, err
}
inParent := false
for _, org := range orgs {
// adding the "." is required here.
if strings.HasPrefix(globalid, org.Globalid+".") {
inParent = true
break
}
}
if !inParent {
return false, nil
}
// add the user
org, err := mgr.GetByName(invite.Organization)
if err != nil {
return false, err
}
if invitations.RoleOwner == invite.Role {
// Accepted Owner role
if err := mgr.SaveOwner(org, username); err != nil {
return false, err
}
} else {
// Accepted member role
if err := mgr.SaveMember(org, username); err != nil {
return false, err
}
}
// set the invite to status accpeted
invite.Status = invitations.RequestAccepted
log.Debug("Invitation auto accepted because the user is already an owner or member of a parent organization")
return true, nil
} | [
"func",
"(",
"api",
"OrganizationsAPI",
")",
"autoAcceptSubOrgInvite",
"(",
"invite",
"*",
"invitations",
".",
"JoinOrganizationInvitation",
",",
"mgr",
"*",
"organization",
".",
"Manager",
")",
"(",
"bool",
",",
"error",
")",
"{",
"globalid",
":=",
"invite",
".",
"Organization",
"\n\n",
"// If this is an invite for a root organization we obviously aren't a member of a parent yet",
"if",
"!",
"strings",
".",
"Contains",
"(",
"globalid",
",",
"\"",
"\"",
")",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"// Check for username so we only auto accept already registered users",
"// Not sure if this is needed but it doesn't hurt to check",
"username",
":=",
"invite",
".",
"User",
"\n",
"if",
"username",
"==",
"\"",
"\"",
"{",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"// Check if we happen to be a member or owner of a parent org",
"orgs",
",",
"err",
":=",
"mgr",
".",
"AllByUser",
"(",
"username",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"inParent",
":=",
"false",
"\n",
"for",
"_",
",",
"org",
":=",
"range",
"orgs",
"{",
"// adding the \".\" is required here.",
"if",
"strings",
".",
"HasPrefix",
"(",
"globalid",
",",
"org",
".",
"Globalid",
"+",
"\"",
"\"",
")",
"{",
"inParent",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"!",
"inParent",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"// add the user",
"org",
",",
"err",
":=",
"mgr",
".",
"GetByName",
"(",
"invite",
".",
"Organization",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"if",
"invitations",
".",
"RoleOwner",
"==",
"invite",
".",
"Role",
"{",
"// Accepted Owner role",
"if",
"err",
":=",
"mgr",
".",
"SaveOwner",
"(",
"org",
",",
"username",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"// Accepted member role",
"if",
"err",
":=",
"mgr",
".",
"SaveMember",
"(",
"org",
",",
"username",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"// set the invite to status accpeted",
"invite",
".",
"Status",
"=",
"invitations",
".",
"RequestAccepted",
"\n",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"true",
",",
"nil",
"\n",
"}"
] | // autoAcceptSubOrgInvite tries to auto accept an invitation if a user is already a member or owner in a parent organization | [
"autoAcceptSubOrgInvite",
"tries",
"to",
"auto",
"accept",
"an",
"invitation",
"if",
"a",
"user",
"is",
"already",
"a",
"member",
"or",
"owner",
"in",
"a",
"parent",
"organization"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/organization/organizations_api.go#L413-L467 |
13,825 | itsyouonline/identityserver | identityservice/organization/organizations_api.go | actualOrganizationDeletion | func (api OrganizationsAPI) actualOrganizationDeletion(r *http.Request, globalid string) error {
orgMgr := organization.NewManager(r)
logoMgr := organization.NewLogoManager(r)
// If the organization does not exist then it should be completely cleaned up already.
// Since the goal of this method is to make sure it does not exist anymore, that goal is already complete
if !orgMgr.Exists(globalid) {
return nil
}
if err := orgMgr.Remove(globalid); err != nil {
return err
}
// Remove the organizations as a member/ an owner of other organizations
organizations, err := orgMgr.AllByOrg(globalid)
if err != nil {
return err
}
for _, org := range organizations {
if err = orgMgr.RemoveOrganization(org.Globalid, globalid); err != nil {
return err
}
}
if logoMgr.Exists(globalid) {
if err = logoMgr.Remove(globalid); err != nil {
return err
}
}
orgReqMgr := invitations.NewInvitationManager(r)
if err = orgReqMgr.RemoveAll(globalid); err != nil {
return err
}
oauthMgr := oauthservice.NewManager(r)
if err = oauthMgr.RemoveTokensByGlobalID(globalid); err != nil {
return err
}
if err = oauthMgr.DeleteAllForOrganization(globalid); err != nil {
return err
}
if err = oauthMgr.RemoveClientsByID(globalid); err != nil {
return err
}
userMgr := user.NewManager(r)
if err = userMgr.DeleteAllAuthorizations(globalid); err != nil {
return err
}
if err = oauthMgr.RemoveClientsByID(globalid); err != nil {
return err
}
l2faMgr := organization.NewLast2FAManager(r)
if err = l2faMgr.RemoveByOrganization(globalid); err != nil {
return err
}
descriptionMgr := organization.NewDescriptionManager(r)
if err = descriptionMgr.Remove(globalid); err != nil {
if !db.IsNotFound(err) {
return err
}
}
if iyoid.NewManager(r).DeleteForClient(globalid); err != nil && !db.IsNotFound(err) {
return err
}
if grants.NewManager(r).DeleteOrgGrants(globalid); err != nil && !db.IsNotFound(err) {
return err
}
return nil
} | go | func (api OrganizationsAPI) actualOrganizationDeletion(r *http.Request, globalid string) error {
orgMgr := organization.NewManager(r)
logoMgr := organization.NewLogoManager(r)
// If the organization does not exist then it should be completely cleaned up already.
// Since the goal of this method is to make sure it does not exist anymore, that goal is already complete
if !orgMgr.Exists(globalid) {
return nil
}
if err := orgMgr.Remove(globalid); err != nil {
return err
}
// Remove the organizations as a member/ an owner of other organizations
organizations, err := orgMgr.AllByOrg(globalid)
if err != nil {
return err
}
for _, org := range organizations {
if err = orgMgr.RemoveOrganization(org.Globalid, globalid); err != nil {
return err
}
}
if logoMgr.Exists(globalid) {
if err = logoMgr.Remove(globalid); err != nil {
return err
}
}
orgReqMgr := invitations.NewInvitationManager(r)
if err = orgReqMgr.RemoveAll(globalid); err != nil {
return err
}
oauthMgr := oauthservice.NewManager(r)
if err = oauthMgr.RemoveTokensByGlobalID(globalid); err != nil {
return err
}
if err = oauthMgr.DeleteAllForOrganization(globalid); err != nil {
return err
}
if err = oauthMgr.RemoveClientsByID(globalid); err != nil {
return err
}
userMgr := user.NewManager(r)
if err = userMgr.DeleteAllAuthorizations(globalid); err != nil {
return err
}
if err = oauthMgr.RemoveClientsByID(globalid); err != nil {
return err
}
l2faMgr := organization.NewLast2FAManager(r)
if err = l2faMgr.RemoveByOrganization(globalid); err != nil {
return err
}
descriptionMgr := organization.NewDescriptionManager(r)
if err = descriptionMgr.Remove(globalid); err != nil {
if !db.IsNotFound(err) {
return err
}
}
if iyoid.NewManager(r).DeleteForClient(globalid); err != nil && !db.IsNotFound(err) {
return err
}
if grants.NewManager(r).DeleteOrgGrants(globalid); err != nil && !db.IsNotFound(err) {
return err
}
return nil
} | [
"func",
"(",
"api",
"OrganizationsAPI",
")",
"actualOrganizationDeletion",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"globalid",
"string",
")",
"error",
"{",
"orgMgr",
":=",
"organization",
".",
"NewManager",
"(",
"r",
")",
"\n",
"logoMgr",
":=",
"organization",
".",
"NewLogoManager",
"(",
"r",
")",
"\n",
"// If the organization does not exist then it should be completely cleaned up already.",
"// Since the goal of this method is to make sure it does not exist anymore, that goal is already complete",
"if",
"!",
"orgMgr",
".",
"Exists",
"(",
"globalid",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"err",
":=",
"orgMgr",
".",
"Remove",
"(",
"globalid",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// Remove the organizations as a member/ an owner of other organizations",
"organizations",
",",
"err",
":=",
"orgMgr",
".",
"AllByOrg",
"(",
"globalid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"org",
":=",
"range",
"organizations",
"{",
"if",
"err",
"=",
"orgMgr",
".",
"RemoveOrganization",
"(",
"org",
".",
"Globalid",
",",
"globalid",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"logoMgr",
".",
"Exists",
"(",
"globalid",
")",
"{",
"if",
"err",
"=",
"logoMgr",
".",
"Remove",
"(",
"globalid",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"orgReqMgr",
":=",
"invitations",
".",
"NewInvitationManager",
"(",
"r",
")",
"\n",
"if",
"err",
"=",
"orgReqMgr",
".",
"RemoveAll",
"(",
"globalid",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"oauthMgr",
":=",
"oauthservice",
".",
"NewManager",
"(",
"r",
")",
"\n",
"if",
"err",
"=",
"oauthMgr",
".",
"RemoveTokensByGlobalID",
"(",
"globalid",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
"=",
"oauthMgr",
".",
"DeleteAllForOrganization",
"(",
"globalid",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
"=",
"oauthMgr",
".",
"RemoveClientsByID",
"(",
"globalid",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"userMgr",
":=",
"user",
".",
"NewManager",
"(",
"r",
")",
"\n",
"if",
"err",
"=",
"userMgr",
".",
"DeleteAllAuthorizations",
"(",
"globalid",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
"=",
"oauthMgr",
".",
"RemoveClientsByID",
"(",
"globalid",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"l2faMgr",
":=",
"organization",
".",
"NewLast2FAManager",
"(",
"r",
")",
"\n",
"if",
"err",
"=",
"l2faMgr",
".",
"RemoveByOrganization",
"(",
"globalid",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"descriptionMgr",
":=",
"organization",
".",
"NewDescriptionManager",
"(",
"r",
")",
"\n",
"if",
"err",
"=",
"descriptionMgr",
".",
"Remove",
"(",
"globalid",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"!",
"db",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"iyoid",
".",
"NewManager",
"(",
"r",
")",
".",
"DeleteForClient",
"(",
"globalid",
")",
";",
"err",
"!=",
"nil",
"&&",
"!",
"db",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"grants",
".",
"NewManager",
"(",
"r",
")",
".",
"DeleteOrgGrants",
"(",
"globalid",
")",
";",
"err",
"!=",
"nil",
"&&",
"!",
"db",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Delete organization with globalid. | [
"Delete",
"organization",
"with",
"globalid",
"."
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/organization/organizations_api.go#L1068-L1133 |
13,826 | itsyouonline/identityserver | identityservice/organization/organizations_api.go | GetUserGrants | func (api OrganizationsAPI) GetUserGrants(w http.ResponseWriter, r *http.Request) {
globalID := mux.Vars(r)["globalid"]
userIdentifier := mux.Vars(r)["username"]
userObj, err := SearchUser(r, userIdentifier)
if err != nil && !db.IsNotFound(err) {
log.Error("Failed to look up user identifier: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
if err != nil {
log.Debug("If the user doesn't exist he also can't have an authorization")
// No user found for this identifier, return an empty list of grants
w.WriteHeader(http.StatusForbidden)
return
}
hasAuth, err := hasAuthorization(r, userObj.Username, globalID)
if handleServerError(w, "checking if user has an authorization for the organization", err) {
return
}
if !hasAuth {
log.Debug("Refusing to list grants for user without authorization")
w.WriteHeader(http.StatusForbidden)
w.Write([]byte("User does not have an authorization for this organzation"))
return
}
grantMgr := grants.NewManager(r)
grantObj, err := grantMgr.GetGrantsForUser(userObj.Username, globalID)
if err != nil && !db.IsNotFound(err) {
log.Error("Failed to look up user grants: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
if db.IsNotFound(err) {
grantObj = &grants.SavedGrants{Grants: []grants.Grant{}}
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(grantObj.Grants)
} | go | func (api OrganizationsAPI) GetUserGrants(w http.ResponseWriter, r *http.Request) {
globalID := mux.Vars(r)["globalid"]
userIdentifier := mux.Vars(r)["username"]
userObj, err := SearchUser(r, userIdentifier)
if err != nil && !db.IsNotFound(err) {
log.Error("Failed to look up user identifier: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
if err != nil {
log.Debug("If the user doesn't exist he also can't have an authorization")
// No user found for this identifier, return an empty list of grants
w.WriteHeader(http.StatusForbidden)
return
}
hasAuth, err := hasAuthorization(r, userObj.Username, globalID)
if handleServerError(w, "checking if user has an authorization for the organization", err) {
return
}
if !hasAuth {
log.Debug("Refusing to list grants for user without authorization")
w.WriteHeader(http.StatusForbidden)
w.Write([]byte("User does not have an authorization for this organzation"))
return
}
grantMgr := grants.NewManager(r)
grantObj, err := grantMgr.GetGrantsForUser(userObj.Username, globalID)
if err != nil && !db.IsNotFound(err) {
log.Error("Failed to look up user grants: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
if db.IsNotFound(err) {
grantObj = &grants.SavedGrants{Grants: []grants.Grant{}}
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(grantObj.Grants)
} | [
"func",
"(",
"api",
"OrganizationsAPI",
")",
"GetUserGrants",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"globalID",
":=",
"mux",
".",
"Vars",
"(",
"r",
")",
"[",
"\"",
"\"",
"]",
"\n",
"userIdentifier",
":=",
"mux",
".",
"Vars",
"(",
"r",
")",
"[",
"\"",
"\"",
"]",
"\n\n",
"userObj",
",",
"err",
":=",
"SearchUser",
"(",
"r",
",",
"userIdentifier",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"db",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"log",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"// No user found for this identifier, return an empty list of grants",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusForbidden",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"hasAuth",
",",
"err",
":=",
"hasAuthorization",
"(",
"r",
",",
"userObj",
".",
"Username",
",",
"globalID",
")",
"\n",
"if",
"handleServerError",
"(",
"w",
",",
"\"",
"\"",
",",
"err",
")",
"{",
"return",
"\n",
"}",
"\n",
"if",
"!",
"hasAuth",
"{",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusForbidden",
")",
"\n",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"grantMgr",
":=",
"grants",
".",
"NewManager",
"(",
"r",
")",
"\n",
"grantObj",
",",
"err",
":=",
"grantMgr",
".",
"GetGrantsForUser",
"(",
"userObj",
".",
"Username",
",",
"globalID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"db",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"log",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"db",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"grantObj",
"=",
"&",
"grants",
".",
"SavedGrants",
"{",
"Grants",
":",
"[",
"]",
"grants",
".",
"Grant",
"{",
"}",
"}",
"\n",
"}",
"\n\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusOK",
")",
"\n",
"json",
".",
"NewEncoder",
"(",
"w",
")",
".",
"Encode",
"(",
"grantObj",
".",
"Grants",
")",
"\n",
"}"
] | // GetUserGrants lists all grants for a user | [
"GetUserGrants",
"lists",
"all",
"grants",
"for",
"a",
"user"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/organization/organizations_api.go#L2219-L2261 |
13,827 | itsyouonline/identityserver | identityservice/organization/organizations_api.go | DeleteUserGrant | func (api OrganizationsAPI) DeleteUserGrant(w http.ResponseWriter, r *http.Request) {
globalid := mux.Vars(r)["globalid"]
userIdentifier := mux.Vars(r)["username"]
grantString := mux.Vars(r)["grant"]
grant := grants.Grant(grantString)
userObj, err := SearchUser(r, userIdentifier)
if err != nil && !db.IsNotFound(err) {
log.Error("Failed to look up user identifier: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
if err != nil {
// No user found for this identifier, since the user thus no longer has the grant requested
// for removal, we can also return a 204 here
w.WriteHeader(http.StatusNoContent)
return
}
hasAuth, err := hasAuthorization(r, userObj.Username, globalid)
if handleServerError(w, "checking if user has an authorization for the organization", err) {
return
}
if !hasAuth {
log.Debug("Refusing to delete grant for user without authorization")
w.WriteHeader(http.StatusForbidden)
w.Write([]byte("User does not have an authorization for this organzation"))
return
}
grantMgr := grants.NewManager(r)
err = grantMgr.DeleteUserGrant(userObj.Username, globalid, grant)
if err != nil && !db.IsNotFound(err) {
log.Error("Failed to delete user grant: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusNoContent)
} | go | func (api OrganizationsAPI) DeleteUserGrant(w http.ResponseWriter, r *http.Request) {
globalid := mux.Vars(r)["globalid"]
userIdentifier := mux.Vars(r)["username"]
grantString := mux.Vars(r)["grant"]
grant := grants.Grant(grantString)
userObj, err := SearchUser(r, userIdentifier)
if err != nil && !db.IsNotFound(err) {
log.Error("Failed to look up user identifier: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
if err != nil {
// No user found for this identifier, since the user thus no longer has the grant requested
// for removal, we can also return a 204 here
w.WriteHeader(http.StatusNoContent)
return
}
hasAuth, err := hasAuthorization(r, userObj.Username, globalid)
if handleServerError(w, "checking if user has an authorization for the organization", err) {
return
}
if !hasAuth {
log.Debug("Refusing to delete grant for user without authorization")
w.WriteHeader(http.StatusForbidden)
w.Write([]byte("User does not have an authorization for this organzation"))
return
}
grantMgr := grants.NewManager(r)
err = grantMgr.DeleteUserGrant(userObj.Username, globalid, grant)
if err != nil && !db.IsNotFound(err) {
log.Error("Failed to delete user grant: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusNoContent)
} | [
"func",
"(",
"api",
"OrganizationsAPI",
")",
"DeleteUserGrant",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"globalid",
":=",
"mux",
".",
"Vars",
"(",
"r",
")",
"[",
"\"",
"\"",
"]",
"\n",
"userIdentifier",
":=",
"mux",
".",
"Vars",
"(",
"r",
")",
"[",
"\"",
"\"",
"]",
"\n",
"grantString",
":=",
"mux",
".",
"Vars",
"(",
"r",
")",
"[",
"\"",
"\"",
"]",
"\n\n",
"grant",
":=",
"grants",
".",
"Grant",
"(",
"grantString",
")",
"\n\n",
"userObj",
",",
"err",
":=",
"SearchUser",
"(",
"r",
",",
"userIdentifier",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"db",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"log",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// No user found for this identifier, since the user thus no longer has the grant requested",
"// for removal, we can also return a 204 here",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusNoContent",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"hasAuth",
",",
"err",
":=",
"hasAuthorization",
"(",
"r",
",",
"userObj",
".",
"Username",
",",
"globalid",
")",
"\n",
"if",
"handleServerError",
"(",
"w",
",",
"\"",
"\"",
",",
"err",
")",
"{",
"return",
"\n",
"}",
"\n",
"if",
"!",
"hasAuth",
"{",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusForbidden",
")",
"\n",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"grantMgr",
":=",
"grants",
".",
"NewManager",
"(",
"r",
")",
"\n",
"err",
"=",
"grantMgr",
".",
"DeleteUserGrant",
"(",
"userObj",
".",
"Username",
",",
"globalid",
",",
"grant",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"db",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"log",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusNoContent",
")",
"\n",
"}"
] | // DeleteUserGrant removes a single named grant for the user | [
"DeleteUserGrant",
"removes",
"a",
"single",
"named",
"grant",
"for",
"the",
"user"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/organization/organizations_api.go#L2264-L2304 |
13,828 | itsyouonline/identityserver | identityservice/organization/organizations_api.go | CreateUserGrant | func (api OrganizationsAPI) CreateUserGrant(w http.ResponseWriter, r *http.Request) {
globalid := mux.Vars(r)["globalid"]
body := struct {
Username string `json:"username"`
Grant grants.Grant `json:"grant"`
}{}
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
log.Debug("Error decoding create grant body:", err)
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return
}
if err := body.Grant.Validate(); err != nil {
log.Debug("Invalid grant: ", err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
userObj, err := SearchUser(r, body.Username)
if err != nil && !db.IsNotFound(err) {
log.Error("Failed to look up user identifier: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
if err != nil {
// We can't give a grant to a user that doesn't exist
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}
hasAuth, err := hasAuthorization(r, userObj.Username, globalid)
if handleServerError(w, "checking if user has an authorization for the organization", err) {
return
}
if !hasAuth {
log.Debug("Refusing to give a grant to a user without authorization")
w.WriteHeader(http.StatusForbidden)
w.Write([]byte("User does not have an authorization for this organzation"))
return
}
grantMgr := grants.NewManager(r)
err = grantMgr.UpserGrant(userObj.Username, globalid, body.Grant)
if err != nil && err != grants.ErrGrantLimitReached {
log.Error("Failed to create user grant: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
if err != nil {
log.Debug("Max amount of grants reached")
http.Error(w, http.StatusText(http.StatusConflict), http.StatusConflict)
}
grantObj, err := grantMgr.GetGrantsForUser(userObj.Username, globalid)
if err != nil {
log.Error("Failed to look up user grants: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
json.NewEncoder(w).Encode(grantObj.Grants)
} | go | func (api OrganizationsAPI) CreateUserGrant(w http.ResponseWriter, r *http.Request) {
globalid := mux.Vars(r)["globalid"]
body := struct {
Username string `json:"username"`
Grant grants.Grant `json:"grant"`
}{}
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
log.Debug("Error decoding create grant body:", err)
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return
}
if err := body.Grant.Validate(); err != nil {
log.Debug("Invalid grant: ", err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
userObj, err := SearchUser(r, body.Username)
if err != nil && !db.IsNotFound(err) {
log.Error("Failed to look up user identifier: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
if err != nil {
// We can't give a grant to a user that doesn't exist
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}
hasAuth, err := hasAuthorization(r, userObj.Username, globalid)
if handleServerError(w, "checking if user has an authorization for the organization", err) {
return
}
if !hasAuth {
log.Debug("Refusing to give a grant to a user without authorization")
w.WriteHeader(http.StatusForbidden)
w.Write([]byte("User does not have an authorization for this organzation"))
return
}
grantMgr := grants.NewManager(r)
err = grantMgr.UpserGrant(userObj.Username, globalid, body.Grant)
if err != nil && err != grants.ErrGrantLimitReached {
log.Error("Failed to create user grant: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
if err != nil {
log.Debug("Max amount of grants reached")
http.Error(w, http.StatusText(http.StatusConflict), http.StatusConflict)
}
grantObj, err := grantMgr.GetGrantsForUser(userObj.Username, globalid)
if err != nil {
log.Error("Failed to look up user grants: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
json.NewEncoder(w).Encode(grantObj.Grants)
} | [
"func",
"(",
"api",
"OrganizationsAPI",
")",
"CreateUserGrant",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"globalid",
":=",
"mux",
".",
"Vars",
"(",
"r",
")",
"[",
"\"",
"\"",
"]",
"\n\n",
"body",
":=",
"struct",
"{",
"Username",
"string",
"`json:\"username\"`",
"\n",
"Grant",
"grants",
".",
"Grant",
"`json:\"grant\"`",
"\n",
"}",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"NewDecoder",
"(",
"r",
".",
"Body",
")",
".",
"Decode",
"(",
"&",
"body",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusBadRequest",
")",
",",
"http",
".",
"StatusBadRequest",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"body",
".",
"Grant",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"err",
".",
"Error",
"(",
")",
",",
"http",
".",
"StatusBadRequest",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"userObj",
",",
"err",
":=",
"SearchUser",
"(",
"r",
",",
"body",
".",
"Username",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"db",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"log",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// We can't give a grant to a user that doesn't exist",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusNotFound",
")",
",",
"http",
".",
"StatusNotFound",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"hasAuth",
",",
"err",
":=",
"hasAuthorization",
"(",
"r",
",",
"userObj",
".",
"Username",
",",
"globalid",
")",
"\n",
"if",
"handleServerError",
"(",
"w",
",",
"\"",
"\"",
",",
"err",
")",
"{",
"return",
"\n",
"}",
"\n",
"if",
"!",
"hasAuth",
"{",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusForbidden",
")",
"\n",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"grantMgr",
":=",
"grants",
".",
"NewManager",
"(",
"r",
")",
"\n",
"err",
"=",
"grantMgr",
".",
"UpserGrant",
"(",
"userObj",
".",
"Username",
",",
"globalid",
",",
"body",
".",
"Grant",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"grants",
".",
"ErrGrantLimitReached",
"{",
"log",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusConflict",
")",
",",
"http",
".",
"StatusConflict",
")",
"\n",
"}",
"\n\n",
"grantObj",
",",
"err",
":=",
"grantMgr",
".",
"GetGrantsForUser",
"(",
"userObj",
".",
"Username",
",",
"globalid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusCreated",
")",
"\n",
"json",
".",
"NewEncoder",
"(",
"w",
")",
".",
"Encode",
"(",
"grantObj",
".",
"Grants",
")",
"\n",
"}"
] | // CreateUserGrant gives a new grant to a user | [
"CreateUserGrant",
"gives",
"a",
"new",
"grant",
"to",
"a",
"user"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/organization/organizations_api.go#L2347-L2412 |
13,829 | itsyouonline/identityserver | identityservice/organization/organizations_api.go | ListUsersWithGrant | func (api OrganizationsAPI) ListUsersWithGrant(w http.ResponseWriter, r *http.Request) {
globalID := mux.Vars(r)["globalid"]
grantString := mux.Vars(r)["grant"]
grant := grants.Grant(grantString)
if err := grant.Validate(); err != nil {
log.Debug("Invalid grant: ", err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
grantMgr := grants.NewManager(r)
grantObjs, err := grantMgr.GetByGrant(grant, globalID)
if err != nil && !db.IsNotFound(err) {
log.Error("Failed to look up users with grant: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
usernames := []string{}
for _, grantObj := range grantObjs {
usernames = append(usernames, grantObj.Username)
}
log.Debug("filtering users to those with an open authorization")
usernames, err = user.NewManager(r).FilterUsersWithAuthorizations(usernames, globalID)
if handleServerError(w, "filtering out users without authorization", err) {
return
}
userIdentifiers, err := organization.ConvertUsernamesToIdentifiers(usernames, validationdb.NewManager(r))
if err != nil {
log.Error("Failed to convert usernames to identifiers: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(userIdentifiers)
} | go | func (api OrganizationsAPI) ListUsersWithGrant(w http.ResponseWriter, r *http.Request) {
globalID := mux.Vars(r)["globalid"]
grantString := mux.Vars(r)["grant"]
grant := grants.Grant(grantString)
if err := grant.Validate(); err != nil {
log.Debug("Invalid grant: ", err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
grantMgr := grants.NewManager(r)
grantObjs, err := grantMgr.GetByGrant(grant, globalID)
if err != nil && !db.IsNotFound(err) {
log.Error("Failed to look up users with grant: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
usernames := []string{}
for _, grantObj := range grantObjs {
usernames = append(usernames, grantObj.Username)
}
log.Debug("filtering users to those with an open authorization")
usernames, err = user.NewManager(r).FilterUsersWithAuthorizations(usernames, globalID)
if handleServerError(w, "filtering out users without authorization", err) {
return
}
userIdentifiers, err := organization.ConvertUsernamesToIdentifiers(usernames, validationdb.NewManager(r))
if err != nil {
log.Error("Failed to convert usernames to identifiers: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(userIdentifiers)
} | [
"func",
"(",
"api",
"OrganizationsAPI",
")",
"ListUsersWithGrant",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"globalID",
":=",
"mux",
".",
"Vars",
"(",
"r",
")",
"[",
"\"",
"\"",
"]",
"\n",
"grantString",
":=",
"mux",
".",
"Vars",
"(",
"r",
")",
"[",
"\"",
"\"",
"]",
"\n\n",
"grant",
":=",
"grants",
".",
"Grant",
"(",
"grantString",
")",
"\n",
"if",
"err",
":=",
"grant",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"err",
".",
"Error",
"(",
")",
",",
"http",
".",
"StatusBadRequest",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"grantMgr",
":=",
"grants",
".",
"NewManager",
"(",
"r",
")",
"\n",
"grantObjs",
",",
"err",
":=",
"grantMgr",
".",
"GetByGrant",
"(",
"grant",
",",
"globalID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"db",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"log",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"usernames",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"grantObj",
":=",
"range",
"grantObjs",
"{",
"usernames",
"=",
"append",
"(",
"usernames",
",",
"grantObj",
".",
"Username",
")",
"\n",
"}",
"\n\n",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"usernames",
",",
"err",
"=",
"user",
".",
"NewManager",
"(",
"r",
")",
".",
"FilterUsersWithAuthorizations",
"(",
"usernames",
",",
"globalID",
")",
"\n",
"if",
"handleServerError",
"(",
"w",
",",
"\"",
"\"",
",",
"err",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"userIdentifiers",
",",
"err",
":=",
"organization",
".",
"ConvertUsernamesToIdentifiers",
"(",
"usernames",
",",
"validationdb",
".",
"NewManager",
"(",
"r",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusOK",
")",
"\n",
"json",
".",
"NewEncoder",
"(",
"w",
")",
".",
"Encode",
"(",
"userIdentifiers",
")",
"\n",
"}"
] | // ListUsersWithGrant lists all users with a given grant | [
"ListUsersWithGrant",
"lists",
"all",
"users",
"with",
"a",
"given",
"grant"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/organization/organizations_api.go#L2510-L2550 |
13,830 | itsyouonline/identityserver | identityservice/organization/organizations_api.go | hasAuthorization | func hasAuthorization(r *http.Request, username string, globalid string) (bool, error) {
userMgr := user.NewManager(r)
authorization, err := userMgr.GetAuthorization(username, globalid)
if err != nil && !db.IsNotFound(err) {
return false, err
}
if authorization == nil || db.IsNotFound(err) {
return false, nil
}
return true, nil
} | go | func hasAuthorization(r *http.Request, username string, globalid string) (bool, error) {
userMgr := user.NewManager(r)
authorization, err := userMgr.GetAuthorization(username, globalid)
if err != nil && !db.IsNotFound(err) {
return false, err
}
if authorization == nil || db.IsNotFound(err) {
return false, nil
}
return true, nil
} | [
"func",
"hasAuthorization",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"username",
"string",
",",
"globalid",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"userMgr",
":=",
"user",
".",
"NewManager",
"(",
"r",
")",
"\n\n",
"authorization",
",",
"err",
":=",
"userMgr",
".",
"GetAuthorization",
"(",
"username",
",",
"globalid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"db",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"if",
"authorization",
"==",
"nil",
"||",
"db",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"return",
"true",
",",
"nil",
"\n",
"}"
] | // hasAuthorization checks if a user has an open authorization for an organization | [
"hasAuthorization",
"checks",
"if",
"a",
"user",
"has",
"an",
"open",
"authorization",
"for",
"an",
"organization"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/organization/organizations_api.go#L2562-L2573 |
13,831 | itsyouonline/identityserver | identityservice/organization/organizations_api.go | SearchUser | func SearchUser(r *http.Request, searchString string) (*user.User, error) {
userMgr := user.NewManager(r)
usr, err := userMgr.GetByName(searchString)
if err == nil {
return usr, err
}
if !db.IsNotFound(err) {
return nil, err
}
valMgr := validationdb.NewManager(r)
validatedPhonenumber, err := valMgr.GetByPhoneNumber(searchString)
if err != nil && !db.IsNotFound(err) {
return nil, err
}
if !db.IsNotFound(err) {
return userMgr.GetByName(validatedPhonenumber.Username)
}
validatedEmailAddress, err := valMgr.GetByEmailAddress(searchString)
if err != nil && !db.IsNotFound(err) {
return nil, err
}
if !db.IsNotFound(err) {
return userMgr.GetByName(validatedEmailAddress.Username)
}
idMgr := iyoid.NewManager(r)
clientID, _ := context.Get(r, "client_id").(string)
idObj, err := idMgr.GetByIDAndAZP(searchString, clientID)
if err != nil {
return nil, err
}
return userMgr.GetByName(idObj.Username)
} | go | func SearchUser(r *http.Request, searchString string) (*user.User, error) {
userMgr := user.NewManager(r)
usr, err := userMgr.GetByName(searchString)
if err == nil {
return usr, err
}
if !db.IsNotFound(err) {
return nil, err
}
valMgr := validationdb.NewManager(r)
validatedPhonenumber, err := valMgr.GetByPhoneNumber(searchString)
if err != nil && !db.IsNotFound(err) {
return nil, err
}
if !db.IsNotFound(err) {
return userMgr.GetByName(validatedPhonenumber.Username)
}
validatedEmailAddress, err := valMgr.GetByEmailAddress(searchString)
if err != nil && !db.IsNotFound(err) {
return nil, err
}
if !db.IsNotFound(err) {
return userMgr.GetByName(validatedEmailAddress.Username)
}
idMgr := iyoid.NewManager(r)
clientID, _ := context.Get(r, "client_id").(string)
idObj, err := idMgr.GetByIDAndAZP(searchString, clientID)
if err != nil {
return nil, err
}
return userMgr.GetByName(idObj.Username)
} | [
"func",
"SearchUser",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"searchString",
"string",
")",
"(",
"*",
"user",
".",
"User",
",",
"error",
")",
"{",
"userMgr",
":=",
"user",
".",
"NewManager",
"(",
"r",
")",
"\n",
"usr",
",",
"err",
":=",
"userMgr",
".",
"GetByName",
"(",
"searchString",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"usr",
",",
"err",
"\n",
"}",
"\n",
"if",
"!",
"db",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"valMgr",
":=",
"validationdb",
".",
"NewManager",
"(",
"r",
")",
"\n",
"validatedPhonenumber",
",",
"err",
":=",
"valMgr",
".",
"GetByPhoneNumber",
"(",
"searchString",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"db",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"!",
"db",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"userMgr",
".",
"GetByName",
"(",
"validatedPhonenumber",
".",
"Username",
")",
"\n",
"}",
"\n",
"validatedEmailAddress",
",",
"err",
":=",
"valMgr",
".",
"GetByEmailAddress",
"(",
"searchString",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"db",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"!",
"db",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"userMgr",
".",
"GetByName",
"(",
"validatedEmailAddress",
".",
"Username",
")",
"\n",
"}",
"\n",
"idMgr",
":=",
"iyoid",
".",
"NewManager",
"(",
"r",
")",
"\n",
"clientID",
",",
"_",
":=",
"context",
".",
"Get",
"(",
"r",
",",
"\"",
"\"",
")",
".",
"(",
"string",
")",
"\n",
"idObj",
",",
"err",
":=",
"idMgr",
".",
"GetByIDAndAZP",
"(",
"searchString",
",",
"clientID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"userMgr",
".",
"GetByName",
"(",
"idObj",
".",
"Username",
")",
"\n",
"}"
] | // SearchUser identifies a user based on a valid user identifier | [
"SearchUser",
"identifies",
"a",
"user",
"based",
"on",
"a",
"valid",
"user",
"identifier"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/organization/organizations_api.go#L2585-L2616 |
13,832 | itsyouonline/identityserver | identityservice/organization/organizations_api.go | parseLangKey | func parseLangKey(rawKey string) string {
if len(rawKey) < 2 {
return ""
}
return strings.ToLower(string(rawKey[0:2]))
} | go | func parseLangKey(rawKey string) string {
if len(rawKey) < 2 {
return ""
}
return strings.ToLower(string(rawKey[0:2]))
} | [
"func",
"parseLangKey",
"(",
"rawKey",
"string",
")",
"string",
"{",
"if",
"len",
"(",
"rawKey",
")",
"<",
"2",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"strings",
".",
"ToLower",
"(",
"string",
"(",
"rawKey",
"[",
"0",
":",
"2",
"]",
")",
")",
"\n",
"}"
] | // parseLangKey return the first 2 characters of a string in lowercase. If the string is empty or has only 1 character, and empty string is returned | [
"parseLangKey",
"return",
"the",
"first",
"2",
"characters",
"of",
"a",
"string",
"in",
"lowercase",
".",
"If",
"the",
"string",
"is",
"empty",
"or",
"has",
"only",
"1",
"character",
"and",
"empty",
"string",
"is",
"returned"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/organization/organizations_api.go#L2619-L2624 |
13,833 | itsyouonline/identityserver | db/model.go | EnsureIndex | func EnsureIndex(collectionName string, index mgo.Index) {
session := GetSession()
defer session.Close()
c := GetCollection(session, collectionName)
// Make sure idices are created.
if err := c.EnsureIndex(index); err == nil {
log.Debugf("Ensured \"%s\" collection indices", collectionName)
} else {
// Important: Mongo3 doesn't support DropDups!
log.Fatalf("Failed to create index on collection \"%s\": %s. Aborting", collectionName, err.Error())
}
} | go | func EnsureIndex(collectionName string, index mgo.Index) {
session := GetSession()
defer session.Close()
c := GetCollection(session, collectionName)
// Make sure idices are created.
if err := c.EnsureIndex(index); err == nil {
log.Debugf("Ensured \"%s\" collection indices", collectionName)
} else {
// Important: Mongo3 doesn't support DropDups!
log.Fatalf("Failed to create index on collection \"%s\": %s. Aborting", collectionName, err.Error())
}
} | [
"func",
"EnsureIndex",
"(",
"collectionName",
"string",
",",
"index",
"mgo",
".",
"Index",
")",
"{",
"session",
":=",
"GetSession",
"(",
")",
"\n",
"defer",
"session",
".",
"Close",
"(",
")",
"\n\n",
"c",
":=",
"GetCollection",
"(",
"session",
",",
"collectionName",
")",
"\n\n",
"// Make sure idices are created.",
"if",
"err",
":=",
"c",
".",
"EnsureIndex",
"(",
"index",
")",
";",
"err",
"==",
"nil",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"collectionName",
")",
"\n",
"}",
"else",
"{",
"// Important: Mongo3 doesn't support DropDups!",
"log",
".",
"Fatalf",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"collectionName",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"}"
] | //EnsureIndex make sure indices are created on certain collection. | [
"EnsureIndex",
"make",
"sure",
"indices",
"are",
"created",
"on",
"certain",
"collection",
"."
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/model.go#L11-L24 |
13,834 | itsyouonline/identityserver | db/model.go | GetCollection | func GetCollection(session *mgo.Session, collectionName string) *mgo.Collection {
return session.DB(DB_NAME).C(collectionName)
} | go | func GetCollection(session *mgo.Session, collectionName string) *mgo.Collection {
return session.DB(DB_NAME).C(collectionName)
} | [
"func",
"GetCollection",
"(",
"session",
"*",
"mgo",
".",
"Session",
",",
"collectionName",
"string",
")",
"*",
"mgo",
".",
"Collection",
"{",
"return",
"session",
".",
"DB",
"(",
"DB_NAME",
")",
".",
"C",
"(",
"collectionName",
")",
"\n",
"}"
] | //GetCollection return collection. | [
"GetCollection",
"return",
"collection",
"."
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/model.go#L27-L29 |
13,835 | itsyouonline/identityserver | db/model.go | GetSession | func GetSession() *mgo.Session {
for {
if session := NewSession(); session != nil {
return session
}
time.Sleep(1 * time.Second)
}
} | go | func GetSession() *mgo.Session {
for {
if session := NewSession(); session != nil {
return session
}
time.Sleep(1 * time.Second)
}
} | [
"func",
"GetSession",
"(",
")",
"*",
"mgo",
".",
"Session",
"{",
"for",
"{",
"if",
"session",
":=",
"NewSession",
"(",
")",
";",
"session",
"!=",
"nil",
"{",
"return",
"session",
"\n",
"}",
"\n\n",
"time",
".",
"Sleep",
"(",
"1",
"*",
"time",
".",
"Second",
")",
"\n",
"}",
"\n",
"}"
] | //GetSession blocking call until session is ready. | [
"GetSession",
"blocking",
"call",
"until",
"session",
"is",
"ready",
"."
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/model.go#L32-L40 |
13,836 | itsyouonline/identityserver | credentials/totp/totp.go | NewToken | func NewToken() (*Token, error) {
byteSecret, err := generateRandomBytes(tokenLength)
secret := base32.StdEncoding.EncodeToString(byteSecret)
return &Token{
Provider: provider,
User: "",
Secret: secret,
}, err
} | go | func NewToken() (*Token, error) {
byteSecret, err := generateRandomBytes(tokenLength)
secret := base32.StdEncoding.EncodeToString(byteSecret)
return &Token{
Provider: provider,
User: "",
Secret: secret,
}, err
} | [
"func",
"NewToken",
"(",
")",
"(",
"*",
"Token",
",",
"error",
")",
"{",
"byteSecret",
",",
"err",
":=",
"generateRandomBytes",
"(",
"tokenLength",
")",
"\n",
"secret",
":=",
"base32",
".",
"StdEncoding",
".",
"EncodeToString",
"(",
"byteSecret",
")",
"\n",
"return",
"&",
"Token",
"{",
"Provider",
":",
"provider",
",",
"User",
":",
"\"",
"\"",
",",
"Secret",
":",
"secret",
",",
"}",
",",
"err",
"\n",
"}"
] | //NewToken creates a new totp token with a random base32 encoded secret | [
"NewToken",
"creates",
"a",
"new",
"totp",
"token",
"with",
"a",
"random",
"base32",
"encoded",
"secret"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/credentials/totp/totp.go#L25-L33 |
13,837 | itsyouonline/identityserver | credentials/totp/totp.go | TokenFromSecret | func TokenFromSecret(secret string) *Token {
return &Token{
Provider: provider,
User: "",
Secret: secret,
}
} | go | func TokenFromSecret(secret string) *Token {
return &Token{
Provider: provider,
User: "",
Secret: secret,
}
} | [
"func",
"TokenFromSecret",
"(",
"secret",
"string",
")",
"*",
"Token",
"{",
"return",
"&",
"Token",
"{",
"Provider",
":",
"provider",
",",
"User",
":",
"\"",
"\"",
",",
"Secret",
":",
"secret",
",",
"}",
"\n",
"}"
] | //TokenFromSecret creates a totp token from an existing base32 encoded secret | [
"TokenFromSecret",
"creates",
"a",
"totp",
"token",
"from",
"an",
"existing",
"base32",
"encoded",
"secret"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/credentials/totp/totp.go#L36-L42 |
13,838 | itsyouonline/identityserver | credentials/totp/totp.go | Validate | func (token *Token) Validate(securityCode string) (valid bool) {
totp := otp.TOTP{
Secret: token.Secret,
IsBase32Secret: true,
}
valid = totp.Now().Verify(securityCode)
return
} | go | func (token *Token) Validate(securityCode string) (valid bool) {
totp := otp.TOTP{
Secret: token.Secret,
IsBase32Secret: true,
}
valid = totp.Now().Verify(securityCode)
return
} | [
"func",
"(",
"token",
"*",
"Token",
")",
"Validate",
"(",
"securityCode",
"string",
")",
"(",
"valid",
"bool",
")",
"{",
"totp",
":=",
"otp",
".",
"TOTP",
"{",
"Secret",
":",
"token",
".",
"Secret",
",",
"IsBase32Secret",
":",
"true",
",",
"}",
"\n",
"valid",
"=",
"totp",
".",
"Now",
"(",
")",
".",
"Verify",
"(",
"securityCode",
")",
"\n",
"return",
"\n\n",
"}"
] | //Validate checks a securityCode against a totp token | [
"Validate",
"checks",
"a",
"securityCode",
"against",
"a",
"totp",
"token"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/credentials/totp/totp.go#L45-L54 |
13,839 | itsyouonline/identityserver | oauthservice/authorize.go | IsAuthorizationValid | func IsAuthorizationValid(possibleScopes []string, authorizedScopes []string) bool {
if len(possibleScopes) > len(authorizedScopes) {
return false
}
POSSIBLESCOPES:
for _, possibleScope := range possibleScopes {
for _, authorizedScope := range authorizedScopes {
if possibleScope == authorizedScope {
// Scope is already authorized, move on to the next one
continue POSSIBLESCOPES
}
}
// If we get here, it means the possibleScope is not in the authorizedScopes list
// So the standing authorization is not valid
return false
}
// Likewise, if we get here we did not yet return due to a missing scope authorization
// and all possible scopes are exhausted. Therefore the standing authorization
// is valid
return true
} | go | func IsAuthorizationValid(possibleScopes []string, authorizedScopes []string) bool {
if len(possibleScopes) > len(authorizedScopes) {
return false
}
POSSIBLESCOPES:
for _, possibleScope := range possibleScopes {
for _, authorizedScope := range authorizedScopes {
if possibleScope == authorizedScope {
// Scope is already authorized, move on to the next one
continue POSSIBLESCOPES
}
}
// If we get here, it means the possibleScope is not in the authorizedScopes list
// So the standing authorization is not valid
return false
}
// Likewise, if we get here we did not yet return due to a missing scope authorization
// and all possible scopes are exhausted. Therefore the standing authorization
// is valid
return true
} | [
"func",
"IsAuthorizationValid",
"(",
"possibleScopes",
"[",
"]",
"string",
",",
"authorizedScopes",
"[",
"]",
"string",
")",
"bool",
"{",
"if",
"len",
"(",
"possibleScopes",
")",
">",
"len",
"(",
"authorizedScopes",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"POSSIBLESCOPES",
":",
"for",
"_",
",",
"possibleScope",
":=",
"range",
"possibleScopes",
"{",
"for",
"_",
",",
"authorizedScope",
":=",
"range",
"authorizedScopes",
"{",
"if",
"possibleScope",
"==",
"authorizedScope",
"{",
"// Scope is already authorized, move on to the next one",
"continue",
"POSSIBLESCOPES",
"\n",
"}",
"\n",
"}",
"\n",
"// If we get here, it means the possibleScope is not in the authorizedScopes list",
"// So the standing authorization is not valid",
"return",
"false",
"\n",
"}",
"\n",
"// Likewise, if we get here we did not yet return due to a missing scope authorization",
"// and all possible scopes are exhausted. Therefore the standing authorization",
"// is valid",
"return",
"true",
"\n",
"}"
] | // IsAuthorizationValid checks if the possible scopes that are being requested are already authorized | [
"IsAuthorizationValid",
"checks",
"if",
"the",
"possible",
"scopes",
"that",
"are",
"being",
"requested",
"are",
"already",
"authorized"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/authorize.go#L308-L328 |
13,840 | itsyouonline/identityserver | siteservice/validation.go | PhonenumberValidation | func (service *Service) PhonenumberValidation(w http.ResponseWriter, request *http.Request) {
service.handlePhoneValidation(w, request, false)
} | go | func (service *Service) PhonenumberValidation(w http.ResponseWriter, request *http.Request) {
service.handlePhoneValidation(w, request, false)
} | [
"func",
"(",
"service",
"*",
"Service",
")",
"PhonenumberValidation",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"request",
"*",
"http",
".",
"Request",
")",
"{",
"service",
".",
"handlePhoneValidation",
"(",
"w",
",",
"request",
",",
"false",
")",
"\n",
"}"
] | //PhonenumberValidation is the page that is linked to in the SMS for phonenumbervalidation and is thus accessed on the mobile phone | [
"PhonenumberValidation",
"is",
"the",
"page",
"that",
"is",
"linked",
"to",
"in",
"the",
"SMS",
"for",
"phonenumbervalidation",
"and",
"is",
"thus",
"accessed",
"on",
"the",
"mobile",
"phone"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/validation.go#L12-L14 |
13,841 | itsyouonline/identityserver | siteservice/validation.go | PhonenumberRegistrationValidation | func (service *Service) PhonenumberRegistrationValidation(w http.ResponseWriter, r *http.Request) {
service.handlePhoneValidation(w, r, true)
} | go | func (service *Service) PhonenumberRegistrationValidation(w http.ResponseWriter, r *http.Request) {
service.handlePhoneValidation(w, r, true)
} | [
"func",
"(",
"service",
"*",
"Service",
")",
"PhonenumberRegistrationValidation",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"service",
".",
"handlePhoneValidation",
"(",
"w",
",",
"r",
",",
"true",
")",
"\n",
"}"
] | // PhonenumberRegistrationValidation handles the sms link in the registration flow | [
"PhonenumberRegistrationValidation",
"handles",
"the",
"sms",
"link",
"in",
"the",
"registration",
"flow"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/validation.go#L17-L19 |
13,842 | itsyouonline/identityserver | siteservice/validation.go | handlePhoneValidation | func (service *Service) handlePhoneValidation(w http.ResponseWriter, request *http.Request, registration bool) {
err := request.ParseForm()
if err != nil {
log.Debug(err)
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return
}
values := request.Form
key := values.Get("k")
smscode := values.Get("c")
langKey := values.Get("l")
translationValues := tools.TranslationValues{
"invalidlink": nil,
"error": nil,
"smsconfirmed": nil,
"return_to_window": nil,
}
translations, err := tools.ParseTranslations(langKey, translationValues)
if err != nil {
log.Error("Failed to parse translations: ", err)
return
}
if registration {
err = service.phonenumberValidationService.ConfirmRegistrationValidation(request, key, smscode)
} else {
err = service.phonenumberValidationService.ConfirmValidation(request, key, smscode)
}
if err == validation.ErrInvalidCode || err == validation.ErrInvalidOrExpiredKey {
service.renderSMSConfirmationPage(w, request, translations["invalidlink"], "")
return
}
if err != nil {
log.Error(err)
service.renderSMSConfirmationPage(w, request, translations["error"], "")
return
}
service.renderSMSConfirmationPage(w, request, translations["smsconfirmed"], translations["return_to_window"])
} | go | func (service *Service) handlePhoneValidation(w http.ResponseWriter, request *http.Request, registration bool) {
err := request.ParseForm()
if err != nil {
log.Debug(err)
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return
}
values := request.Form
key := values.Get("k")
smscode := values.Get("c")
langKey := values.Get("l")
translationValues := tools.TranslationValues{
"invalidlink": nil,
"error": nil,
"smsconfirmed": nil,
"return_to_window": nil,
}
translations, err := tools.ParseTranslations(langKey, translationValues)
if err != nil {
log.Error("Failed to parse translations: ", err)
return
}
if registration {
err = service.phonenumberValidationService.ConfirmRegistrationValidation(request, key, smscode)
} else {
err = service.phonenumberValidationService.ConfirmValidation(request, key, smscode)
}
if err == validation.ErrInvalidCode || err == validation.ErrInvalidOrExpiredKey {
service.renderSMSConfirmationPage(w, request, translations["invalidlink"], "")
return
}
if err != nil {
log.Error(err)
service.renderSMSConfirmationPage(w, request, translations["error"], "")
return
}
service.renderSMSConfirmationPage(w, request, translations["smsconfirmed"], translations["return_to_window"])
} | [
"func",
"(",
"service",
"*",
"Service",
")",
"handlePhoneValidation",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"request",
"*",
"http",
".",
"Request",
",",
"registration",
"bool",
")",
"{",
"err",
":=",
"request",
".",
"ParseForm",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Debug",
"(",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusBadRequest",
")",
",",
"http",
".",
"StatusBadRequest",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"values",
":=",
"request",
".",
"Form",
"\n",
"key",
":=",
"values",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"smscode",
":=",
"values",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"langKey",
":=",
"values",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n\n",
"translationValues",
":=",
"tools",
".",
"TranslationValues",
"{",
"\"",
"\"",
":",
"nil",
",",
"\"",
"\"",
":",
"nil",
",",
"\"",
"\"",
":",
"nil",
",",
"\"",
"\"",
":",
"nil",
",",
"}",
"\n\n",
"translations",
",",
"err",
":=",
"tools",
".",
"ParseTranslations",
"(",
"langKey",
",",
"translationValues",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"registration",
"{",
"err",
"=",
"service",
".",
"phonenumberValidationService",
".",
"ConfirmRegistrationValidation",
"(",
"request",
",",
"key",
",",
"smscode",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"service",
".",
"phonenumberValidationService",
".",
"ConfirmValidation",
"(",
"request",
",",
"key",
",",
"smscode",
")",
"\n",
"}",
"\n",
"if",
"err",
"==",
"validation",
".",
"ErrInvalidCode",
"||",
"err",
"==",
"validation",
".",
"ErrInvalidOrExpiredKey",
"{",
"service",
".",
"renderSMSConfirmationPage",
"(",
"w",
",",
"request",
",",
"translations",
"[",
"\"",
"\"",
"]",
",",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"err",
")",
"\n",
"service",
".",
"renderSMSConfirmationPage",
"(",
"w",
",",
"request",
",",
"translations",
"[",
"\"",
"\"",
"]",
",",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"service",
".",
"renderSMSConfirmationPage",
"(",
"w",
",",
"request",
",",
"translations",
"[",
"\"",
"\"",
"]",
",",
"translations",
"[",
"\"",
"\"",
"]",
")",
"\n",
"}"
] | // handlePohneValidation is the actual handling of phone validation pages. | [
"handlePohneValidation",
"is",
"the",
"actual",
"handling",
"of",
"phone",
"validation",
"pages",
"."
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/validation.go#L22-L64 |
13,843 | itsyouonline/identityserver | siteservice/validation.go | EmailValidation | func (service *Service) EmailValidation(w http.ResponseWriter, request *http.Request) {
service.handleEmailValidation(w, request, false)
} | go | func (service *Service) EmailValidation(w http.ResponseWriter, request *http.Request) {
service.handleEmailValidation(w, request, false)
} | [
"func",
"(",
"service",
"*",
"Service",
")",
"EmailValidation",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"request",
"*",
"http",
".",
"Request",
")",
"{",
"service",
".",
"handleEmailValidation",
"(",
"w",
",",
"request",
",",
"false",
")",
"\n",
"}"
] | // EmailValidation is the page linked to the confirm email button in the email validation email | [
"EmailValidation",
"is",
"the",
"page",
"linked",
"to",
"the",
"confirm",
"email",
"button",
"in",
"the",
"email",
"validation",
"email"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/validation.go#L67-L70 |
13,844 | itsyouonline/identityserver | siteservice/validation.go | EmailRegistrationValidation | func (service *Service) EmailRegistrationValidation(w http.ResponseWriter, r *http.Request) {
service.handleEmailValidation(w, r, true)
} | go | func (service *Service) EmailRegistrationValidation(w http.ResponseWriter, r *http.Request) {
service.handleEmailValidation(w, r, true)
} | [
"func",
"(",
"service",
"*",
"Service",
")",
"EmailRegistrationValidation",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"service",
".",
"handleEmailValidation",
"(",
"w",
",",
"r",
",",
"true",
")",
"\n",
"}"
] | // EmailRegistrationValidation handles the email validation in the login flow | [
"EmailRegistrationValidation",
"handles",
"the",
"email",
"validation",
"in",
"the",
"login",
"flow"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/validation.go#L73-L75 |
13,845 | itsyouonline/identityserver | siteservice/forgetAccount.go | ServeForgetAccountPage | func (service *Service) ServeForgetAccountPage(w http.ResponseWriter, r *http.Request) {
// If we are not in a test environment, we pretend this does not exist
// Don't worry about it
if !service.testEnv {
http.Error(w, "404 page not found", http.StatusNotFound)
return
}
const template = `
<html>
<body>
<h1>Itsyou.online forget validated info</h1>
<form id="mainform" action="delete" method="post">
login:<br/>
<input type="text" id="login" name="login" placeholder="login" required /><br/>
password:<br/>
<input type="password" name="password" placeholder="password" required /><br/>
<br/>
<button type="submit">Log in</button>
</form>
</body>
</html>`
w.WriteHeader(http.StatusOK)
w.Write([]byte(template))
} | go | func (service *Service) ServeForgetAccountPage(w http.ResponseWriter, r *http.Request) {
// If we are not in a test environment, we pretend this does not exist
// Don't worry about it
if !service.testEnv {
http.Error(w, "404 page not found", http.StatusNotFound)
return
}
const template = `
<html>
<body>
<h1>Itsyou.online forget validated info</h1>
<form id="mainform" action="delete" method="post">
login:<br/>
<input type="text" id="login" name="login" placeholder="login" required /><br/>
password:<br/>
<input type="password" name="password" placeholder="password" required /><br/>
<br/>
<button type="submit">Log in</button>
</form>
</body>
</html>`
w.WriteHeader(http.StatusOK)
w.Write([]byte(template))
} | [
"func",
"(",
"service",
"*",
"Service",
")",
"ServeForgetAccountPage",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"// If we are not in a test environment, we pretend this does not exist",
"// Don't worry about it",
"if",
"!",
"service",
".",
"testEnv",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"\"",
"\"",
",",
"http",
".",
"StatusNotFound",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"const",
"template",
"=",
"`\n\t<html>\n\t\t<body>\n\t\t\t<h1>Itsyou.online forget validated info</h1>\n\t\t\t<form id=\"mainform\" action=\"delete\" method=\"post\">\n\t\t\t\tlogin:<br/>\n\t\t\t\t<input type=\"text\" id=\"login\" name=\"login\" placeholder=\"login\" required /><br/>\n\t\t\t\tpassword:<br/>\n\t\t\t\t<input type=\"password\" name=\"password\" placeholder=\"password\" required /><br/>\n\t\t\t\t<br/>\n\t\t\t\t<button type=\"submit\">Log in</button>\n\t\t\t</form>\n\t\t</body>\n\t</html>`",
"\n\n",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusOK",
")",
"\n",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"template",
")",
")",
"\n\n",
"}"
] | // This file contains the forget account handlers. These should only be available in dev and testing envs, indicated with a cli flag
// ServeForgetAccountPage serves the forget account page | [
"This",
"file",
"contains",
"the",
"forget",
"account",
"handlers",
".",
"These",
"should",
"only",
"be",
"available",
"in",
"dev",
"and",
"testing",
"envs",
"indicated",
"with",
"a",
"cli",
"flag",
"ServeForgetAccountPage",
"serves",
"the",
"forget",
"account",
"page"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/forgetAccount.go#L17-L43 |
13,846 | itsyouonline/identityserver | siteservice/forgetAccount.go | ForgetAccountHandler | func (service *Service) ForgetAccountHandler(w http.ResponseWriter, r *http.Request) {
// If we are not in a test environment, we pretend this does not exist
// Don't worry about it
if !service.testEnv {
http.Error(w, "404 page not found", http.StatusNotFound)
return
}
r.ParseForm()
login := strings.ToLower(r.FormValue("login"))
u, err := organization.SearchUser(r, login)
if db.IsNotFound(err) {
w.WriteHeader(422)
return
} else if err != nil {
log.Error("Failed to search for user: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
userexists := !db.IsNotFound(err)
var validpassword bool
passwdMgr := password.NewManager(r)
if validpassword, err = passwdMgr.Validate(u.Username, r.FormValue("password")); err != nil {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
if !userexists || !validpassword {
w.WriteHeader(422)
log.Debug("Invalid password for forgetting user")
return
}
// drop validated info
valMgr := validation.NewManager(r)
validatedEmails, err := valMgr.GetByUsernameValidatedEmailAddress(u.Username)
if err != nil {
log.Error("Failed to get validated email addresses: ", err)
return
}
for _, ve := range validatedEmails {
// I can't be asked to care about the errors here, its past 11.30PM and its only for dev/staging anyway
valMgr.RemoveValidatedEmailAddress(u.Username, ve.EmailAddress)
}
validatedPhones, err := valMgr.GetByUsernameValidatedPhonenumbers(u.Username)
if err != nil {
log.Error("Failed to get validated phone numbers: ", err)
return
}
for _, vp := range validatedPhones {
// Same as above
valMgr.RemoveValidatedPhonenumber(u.Username, vp.Phonenumber)
}
w.WriteHeader(http.StatusOK)
const template = `
<html>
<body>
<h3>
Your validated info has been forgotten and can now be reused
</h3>
</body>
</html>
`
w.Write([]byte(template))
} | go | func (service *Service) ForgetAccountHandler(w http.ResponseWriter, r *http.Request) {
// If we are not in a test environment, we pretend this does not exist
// Don't worry about it
if !service.testEnv {
http.Error(w, "404 page not found", http.StatusNotFound)
return
}
r.ParseForm()
login := strings.ToLower(r.FormValue("login"))
u, err := organization.SearchUser(r, login)
if db.IsNotFound(err) {
w.WriteHeader(422)
return
} else if err != nil {
log.Error("Failed to search for user: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
userexists := !db.IsNotFound(err)
var validpassword bool
passwdMgr := password.NewManager(r)
if validpassword, err = passwdMgr.Validate(u.Username, r.FormValue("password")); err != nil {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
if !userexists || !validpassword {
w.WriteHeader(422)
log.Debug("Invalid password for forgetting user")
return
}
// drop validated info
valMgr := validation.NewManager(r)
validatedEmails, err := valMgr.GetByUsernameValidatedEmailAddress(u.Username)
if err != nil {
log.Error("Failed to get validated email addresses: ", err)
return
}
for _, ve := range validatedEmails {
// I can't be asked to care about the errors here, its past 11.30PM and its only for dev/staging anyway
valMgr.RemoveValidatedEmailAddress(u.Username, ve.EmailAddress)
}
validatedPhones, err := valMgr.GetByUsernameValidatedPhonenumbers(u.Username)
if err != nil {
log.Error("Failed to get validated phone numbers: ", err)
return
}
for _, vp := range validatedPhones {
// Same as above
valMgr.RemoveValidatedPhonenumber(u.Username, vp.Phonenumber)
}
w.WriteHeader(http.StatusOK)
const template = `
<html>
<body>
<h3>
Your validated info has been forgotten and can now be reused
</h3>
</body>
</html>
`
w.Write([]byte(template))
} | [
"func",
"(",
"service",
"*",
"Service",
")",
"ForgetAccountHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"// If we are not in a test environment, we pretend this does not exist",
"// Don't worry about it",
"if",
"!",
"service",
".",
"testEnv",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"\"",
"\"",
",",
"http",
".",
"StatusNotFound",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"r",
".",
"ParseForm",
"(",
")",
"\n",
"login",
":=",
"strings",
".",
"ToLower",
"(",
"r",
".",
"FormValue",
"(",
"\"",
"\"",
")",
")",
"\n\n",
"u",
",",
"err",
":=",
"organization",
".",
"SearchUser",
"(",
"r",
",",
"login",
")",
"\n",
"if",
"db",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"w",
".",
"WriteHeader",
"(",
"422",
")",
"\n",
"return",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n",
"userexists",
":=",
"!",
"db",
".",
"IsNotFound",
"(",
"err",
")",
"\n\n",
"var",
"validpassword",
"bool",
"\n",
"passwdMgr",
":=",
"password",
".",
"NewManager",
"(",
"r",
")",
"\n",
"if",
"validpassword",
",",
"err",
"=",
"passwdMgr",
".",
"Validate",
"(",
"u",
".",
"Username",
",",
"r",
".",
"FormValue",
"(",
"\"",
"\"",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"!",
"userexists",
"||",
"!",
"validpassword",
"{",
"w",
".",
"WriteHeader",
"(",
"422",
")",
"\n",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// drop validated info",
"valMgr",
":=",
"validation",
".",
"NewManager",
"(",
"r",
")",
"\n",
"validatedEmails",
",",
"err",
":=",
"valMgr",
".",
"GetByUsernameValidatedEmailAddress",
"(",
"u",
".",
"Username",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"ve",
":=",
"range",
"validatedEmails",
"{",
"// I can't be asked to care about the errors here, its past 11.30PM and its only for dev/staging anyway",
"valMgr",
".",
"RemoveValidatedEmailAddress",
"(",
"u",
".",
"Username",
",",
"ve",
".",
"EmailAddress",
")",
"\n",
"}",
"\n\n",
"validatedPhones",
",",
"err",
":=",
"valMgr",
".",
"GetByUsernameValidatedPhonenumbers",
"(",
"u",
".",
"Username",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"vp",
":=",
"range",
"validatedPhones",
"{",
"// Same as above",
"valMgr",
".",
"RemoveValidatedPhonenumber",
"(",
"u",
".",
"Username",
",",
"vp",
".",
"Phonenumber",
")",
"\n",
"}",
"\n\n",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusOK",
")",
"\n\n",
"const",
"template",
"=",
"`\n\t<html>\n\t\t<body>\n\t\t\t<h3>\n\t\t\t\tYour validated info has been forgotten and can now be reused\n\t\t\t</h3>\n\t\t</body>\n\t</html>\n\t`",
"\n\n",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"template",
")",
")",
"\n",
"}"
] | // ForgetAccountHandler handles the actuall "forgetting" of an account, by dropping the validated email and phone numbers
// from the respective collections | [
"ForgetAccountHandler",
"handles",
"the",
"actuall",
"forgetting",
"of",
"an",
"account",
"by",
"dropping",
"the",
"validated",
"email",
"and",
"phone",
"numbers",
"from",
"the",
"respective",
"collections"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/forgetAccount.go#L47-L119 |
13,847 | itsyouonline/identityserver | validation/phonenumber.go | RequestValidation | func (service *IYOPhonenumberValidationService) RequestValidation(request *http.Request, username string, phonenumber user.Phonenumber, confirmationurl string, langKey string) (key string, err error) {
valMngr := validation.NewManager(request)
info, err := valMngr.NewPhonenumberValidationInformation(username, phonenumber)
if err != nil {
return
}
err = valMngr.SavePhonenumberValidationInformation(info)
if err != nil {
return
}
translationValues := tools.TranslationValues{
"smsconfirmation": struct {
Code string
Link string
}{
Code: info.SMSCode,
Link: fmt.Sprintf("%s?c=%s&k=%s&l=%s", confirmationurl, info.SMSCode, url.QueryEscape(info.Key), langKey),
},
}
translations, err := tools.ParseTranslations(langKey, translationValues)
if err != nil {
log.Error("Failed to parse translations: ", err)
return
}
go service.SMSService.Send(phonenumber.Phonenumber, translations["smsconfirmation"])
key = info.Key
return
} | go | func (service *IYOPhonenumberValidationService) RequestValidation(request *http.Request, username string, phonenumber user.Phonenumber, confirmationurl string, langKey string) (key string, err error) {
valMngr := validation.NewManager(request)
info, err := valMngr.NewPhonenumberValidationInformation(username, phonenumber)
if err != nil {
return
}
err = valMngr.SavePhonenumberValidationInformation(info)
if err != nil {
return
}
translationValues := tools.TranslationValues{
"smsconfirmation": struct {
Code string
Link string
}{
Code: info.SMSCode,
Link: fmt.Sprintf("%s?c=%s&k=%s&l=%s", confirmationurl, info.SMSCode, url.QueryEscape(info.Key), langKey),
},
}
translations, err := tools.ParseTranslations(langKey, translationValues)
if err != nil {
log.Error("Failed to parse translations: ", err)
return
}
go service.SMSService.Send(phonenumber.Phonenumber, translations["smsconfirmation"])
key = info.Key
return
} | [
"func",
"(",
"service",
"*",
"IYOPhonenumberValidationService",
")",
"RequestValidation",
"(",
"request",
"*",
"http",
".",
"Request",
",",
"username",
"string",
",",
"phonenumber",
"user",
".",
"Phonenumber",
",",
"confirmationurl",
"string",
",",
"langKey",
"string",
")",
"(",
"key",
"string",
",",
"err",
"error",
")",
"{",
"valMngr",
":=",
"validation",
".",
"NewManager",
"(",
"request",
")",
"\n",
"info",
",",
"err",
":=",
"valMngr",
".",
"NewPhonenumberValidationInformation",
"(",
"username",
",",
"phonenumber",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"err",
"=",
"valMngr",
".",
"SavePhonenumberValidationInformation",
"(",
"info",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"translationValues",
":=",
"tools",
".",
"TranslationValues",
"{",
"\"",
"\"",
":",
"struct",
"{",
"Code",
"string",
"\n",
"Link",
"string",
"\n",
"}",
"{",
"Code",
":",
"info",
".",
"SMSCode",
",",
"Link",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"confirmationurl",
",",
"info",
".",
"SMSCode",
",",
"url",
".",
"QueryEscape",
"(",
"info",
".",
"Key",
")",
",",
"langKey",
")",
",",
"}",
",",
"}",
"\n\n",
"translations",
",",
"err",
":=",
"tools",
".",
"ParseTranslations",
"(",
"langKey",
",",
"translationValues",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"go",
"service",
".",
"SMSService",
".",
"Send",
"(",
"phonenumber",
".",
"Phonenumber",
",",
"translations",
"[",
"\"",
"\"",
"]",
")",
"\n",
"key",
"=",
"info",
".",
"Key",
"\n",
"return",
"\n",
"}"
] | //RequestValidation validates the phonenumber by sending an SMS | [
"RequestValidation",
"validates",
"the",
"phonenumber",
"by",
"sending",
"an",
"SMS"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/validation/phonenumber.go#L26-L56 |
13,848 | itsyouonline/identityserver | validation/phonenumber.go | ConfirmRegistrationValidation | func (service *IYOPhonenumberValidationService) ConfirmRegistrationValidation(r *http.Request, key, code string) (err error) {
info, err := service.getPhonenumberValidationInformation(r, key)
if err != nil {
return
}
if info == nil {
err = ErrInvalidOrExpiredKey
return
}
if info.SMSCode != code {
err = ErrInvalidCode
return
}
return validation.NewManager(r).UpdatePhonenumberValidationInformation(key, true)
} | go | func (service *IYOPhonenumberValidationService) ConfirmRegistrationValidation(r *http.Request, key, code string) (err error) {
info, err := service.getPhonenumberValidationInformation(r, key)
if err != nil {
return
}
if info == nil {
err = ErrInvalidOrExpiredKey
return
}
if info.SMSCode != code {
err = ErrInvalidCode
return
}
return validation.NewManager(r).UpdatePhonenumberValidationInformation(key, true)
} | [
"func",
"(",
"service",
"*",
"IYOPhonenumberValidationService",
")",
"ConfirmRegistrationValidation",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"key",
",",
"code",
"string",
")",
"(",
"err",
"error",
")",
"{",
"info",
",",
"err",
":=",
"service",
".",
"getPhonenumberValidationInformation",
"(",
"r",
",",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"info",
"==",
"nil",
"{",
"err",
"=",
"ErrInvalidOrExpiredKey",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"info",
".",
"SMSCode",
"!=",
"code",
"{",
"err",
"=",
"ErrInvalidCode",
"\n",
"return",
"\n",
"}",
"\n",
"return",
"validation",
".",
"NewManager",
"(",
"r",
")",
".",
"UpdatePhonenumberValidationInformation",
"(",
"key",
",",
"true",
")",
"\n",
"}"
] | // ConfirmRegistrationValidation confirms a validation in the registartion flow. It does not add an entry in the validated
// phone numbers collection | [
"ConfirmRegistrationValidation",
"confirms",
"a",
"validation",
"in",
"the",
"registartion",
"flow",
".",
"It",
"does",
"not",
"add",
"an",
"entry",
"in",
"the",
"validated",
"phone",
"numbers",
"collection"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/validation/phonenumber.go#L120-L134 |
13,849 | itsyouonline/identityserver | validation/phonenumber.go | SendOrganizationInviteSms | func (service *IYOPhonenumberValidationService) SendOrganizationInviteSms(request *http.Request, invite *invitations.JoinOrganizationInvitation) (err error) {
link := fmt.Sprintf(invitations.InviteURL, request.Host, url.QueryEscape(invite.Code))
// todo: perhaps this should be shorter but that might be confusing for the end user
message := fmt.Sprintf("You have been invited to the %s organization on It's You Online. Click the following link to accept it. %s", invite.Organization, link)
go service.SMSService.Send(invite.PhoneNumber, message)
return
} | go | func (service *IYOPhonenumberValidationService) SendOrganizationInviteSms(request *http.Request, invite *invitations.JoinOrganizationInvitation) (err error) {
link := fmt.Sprintf(invitations.InviteURL, request.Host, url.QueryEscape(invite.Code))
// todo: perhaps this should be shorter but that might be confusing for the end user
message := fmt.Sprintf("You have been invited to the %s organization on It's You Online. Click the following link to accept it. %s", invite.Organization, link)
go service.SMSService.Send(invite.PhoneNumber, message)
return
} | [
"func",
"(",
"service",
"*",
"IYOPhonenumberValidationService",
")",
"SendOrganizationInviteSms",
"(",
"request",
"*",
"http",
".",
"Request",
",",
"invite",
"*",
"invitations",
".",
"JoinOrganizationInvitation",
")",
"(",
"err",
"error",
")",
"{",
"link",
":=",
"fmt",
".",
"Sprintf",
"(",
"invitations",
".",
"InviteURL",
",",
"request",
".",
"Host",
",",
"url",
".",
"QueryEscape",
"(",
"invite",
".",
"Code",
")",
")",
"\n",
"// todo: perhaps this should be shorter but that might be confusing for the end user",
"message",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"invite",
".",
"Organization",
",",
"link",
")",
"\n",
"go",
"service",
".",
"SMSService",
".",
"Send",
"(",
"invite",
".",
"PhoneNumber",
",",
"message",
")",
"\n",
"return",
"\n",
"}"
] | //SendOrganizationInviteSms Sends an organization invite SMS | [
"SendOrganizationInviteSms",
"Sends",
"an",
"organization",
"invite",
"SMS"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/validation/phonenumber.go#L137-L143 |
13,850 | itsyouonline/identityserver | siteservice/service.go | ShowPublicSite | func (service *Service) ShowPublicSite(w http.ResponseWriter, request *http.Request) {
htmlData, err := html.Asset(mainpageFileName)
if err != nil {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
w.Write(htmlData)
} | go | func (service *Service) ShowPublicSite(w http.ResponseWriter, request *http.Request) {
htmlData, err := html.Asset(mainpageFileName)
if err != nil {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
w.Write(htmlData)
} | [
"func",
"(",
"service",
"*",
"Service",
")",
"ShowPublicSite",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"request",
"*",
"http",
".",
"Request",
")",
"{",
"htmlData",
",",
"err",
":=",
"html",
".",
"Asset",
"(",
"mainpageFileName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n",
"w",
".",
"Write",
"(",
"htmlData",
")",
"\n",
"}"
] | //ShowPublicSite shows the public website | [
"ShowPublicSite",
"shows",
"the",
"public",
"website"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/service.go#L165-L172 |
13,851 | itsyouonline/identityserver | siteservice/service.go | HomePage | func (service *Service) HomePage(w http.ResponseWriter, request *http.Request) {
loggedinuser, err := service.GetLoggedInUser(request, w)
if err != nil {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
if loggedinuser == "" {
service.ShowPublicSite(w, request)
return
}
htmlData, err := html.Asset(homepageFileName)
if err != nil {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
sessions.Save(request, w)
w.Write(htmlData)
} | go | func (service *Service) HomePage(w http.ResponseWriter, request *http.Request) {
loggedinuser, err := service.GetLoggedInUser(request, w)
if err != nil {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
if loggedinuser == "" {
service.ShowPublicSite(w, request)
return
}
htmlData, err := html.Asset(homepageFileName)
if err != nil {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
sessions.Save(request, w)
w.Write(htmlData)
} | [
"func",
"(",
"service",
"*",
"Service",
")",
"HomePage",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"request",
"*",
"http",
".",
"Request",
")",
"{",
"loggedinuser",
",",
"err",
":=",
"service",
".",
"GetLoggedInUser",
"(",
"request",
",",
"w",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"loggedinuser",
"==",
"\"",
"\"",
"{",
"service",
".",
"ShowPublicSite",
"(",
"w",
",",
"request",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"htmlData",
",",
"err",
":=",
"html",
".",
"Asset",
"(",
"homepageFileName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n",
"sessions",
".",
"Save",
"(",
"request",
",",
"w",
")",
"\n",
"w",
".",
"Write",
"(",
"htmlData",
")",
"\n",
"}"
] | //HomePage shows the home page when logged in, if not, delegate to showing the public website | [
"HomePage",
"shows",
"the",
"home",
"page",
"when",
"logged",
"in",
"if",
"not",
"delegate",
"to",
"showing",
"the",
"public",
"website"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/service.go#L185-L204 |
13,852 | itsyouonline/identityserver | siteservice/service.go | ErrorPage | func (service *Service) ErrorPage(w http.ResponseWriter, request *http.Request) {
errornumber := mux.Vars(request)["errornumber"]
log.Debug("Errorpage requested for error ", errornumber)
htmlData, err := html.Asset(errorpageFilename)
if err != nil {
log.Error("ERROR rendering error page: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
// check if the error is a number to prevent XSS attacks
errorcode, err := strconv.Atoi(errornumber)
if err != nil {
log.Info("Error code could not be converted to int")
// The error page already loaded so we might as well use it
errorcode = 400
errornumber = "400"
}
// check if the error code is within the accepted 4xx client or 5xx server error range
if errorcode > 599 || errorcode < 400 {
log.Info("Error code out of bounds: ", errorcode)
errorcode = 400
errornumber = "400"
}
// now that we confirmed the error code is valid, we can safely use it to display on the error page
htmlData = bytes.Replace(htmlData, []byte(`500`), []byte(errornumber), 1)
w.Write(htmlData)
} | go | func (service *Service) ErrorPage(w http.ResponseWriter, request *http.Request) {
errornumber := mux.Vars(request)["errornumber"]
log.Debug("Errorpage requested for error ", errornumber)
htmlData, err := html.Asset(errorpageFilename)
if err != nil {
log.Error("ERROR rendering error page: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
// check if the error is a number to prevent XSS attacks
errorcode, err := strconv.Atoi(errornumber)
if err != nil {
log.Info("Error code could not be converted to int")
// The error page already loaded so we might as well use it
errorcode = 400
errornumber = "400"
}
// check if the error code is within the accepted 4xx client or 5xx server error range
if errorcode > 599 || errorcode < 400 {
log.Info("Error code out of bounds: ", errorcode)
errorcode = 400
errornumber = "400"
}
// now that we confirmed the error code is valid, we can safely use it to display on the error page
htmlData = bytes.Replace(htmlData, []byte(`500`), []byte(errornumber), 1)
w.Write(htmlData)
} | [
"func",
"(",
"service",
"*",
"Service",
")",
"ErrorPage",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"request",
"*",
"http",
".",
"Request",
")",
"{",
"errornumber",
":=",
"mux",
".",
"Vars",
"(",
"request",
")",
"[",
"\"",
"\"",
"]",
"\n",
"log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"errornumber",
")",
"\n\n",
"htmlData",
",",
"err",
":=",
"html",
".",
"Asset",
"(",
"errorpageFilename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// check if the error is a number to prevent XSS attacks",
"errorcode",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"errornumber",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"// The error page already loaded so we might as well use it",
"errorcode",
"=",
"400",
"\n",
"errornumber",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// check if the error code is within the accepted 4xx client or 5xx server error range",
"if",
"errorcode",
">",
"599",
"||",
"errorcode",
"<",
"400",
"{",
"log",
".",
"Info",
"(",
"\"",
"\"",
",",
"errorcode",
")",
"\n",
"errorcode",
"=",
"400",
"\n",
"errornumber",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// now that we confirmed the error code is valid, we can safely use it to display on the error page",
"htmlData",
"=",
"bytes",
".",
"Replace",
"(",
"htmlData",
",",
"[",
"]",
"byte",
"(",
"`500`",
")",
",",
"[",
"]",
"byte",
"(",
"errornumber",
")",
",",
"1",
")",
"\n",
"w",
".",
"Write",
"(",
"htmlData",
")",
"\n",
"}"
] | //ErrorPage shows the errorpage | [
"ErrorPage",
"shows",
"the",
"errorpage"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/service.go#L215-L245 |
13,853 | itsyouonline/identityserver | siteservice/service.go | renderSMSConfirmationPage | func (service *Service) renderSMSConfirmationPage(w http.ResponseWriter, request *http.Request, text string, extratext string) {
htmlData, err := html.Asset(smsconfirmationPage)
if err != nil {
log.Error(err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
htmlData = bytes.Replace(htmlData, []byte(`{{ text }}`), []byte(text), 1)
htmlData = bytes.Replace(htmlData, []byte(`{{ extratext }}`), []byte(extratext), 1)
sessions.Save(request, w)
w.Write(htmlData)
} | go | func (service *Service) renderSMSConfirmationPage(w http.ResponseWriter, request *http.Request, text string, extratext string) {
htmlData, err := html.Asset(smsconfirmationPage)
if err != nil {
log.Error(err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
htmlData = bytes.Replace(htmlData, []byte(`{{ text }}`), []byte(text), 1)
htmlData = bytes.Replace(htmlData, []byte(`{{ extratext }}`), []byte(extratext), 1)
sessions.Save(request, w)
w.Write(htmlData)
} | [
"func",
"(",
"service",
"*",
"Service",
")",
"renderSMSConfirmationPage",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"request",
"*",
"http",
".",
"Request",
",",
"text",
"string",
",",
"extratext",
"string",
")",
"{",
"htmlData",
",",
"err",
":=",
"html",
".",
"Asset",
"(",
"smsconfirmationPage",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n",
"htmlData",
"=",
"bytes",
".",
"Replace",
"(",
"htmlData",
",",
"[",
"]",
"byte",
"(",
"`{{ text }}`",
")",
",",
"[",
"]",
"byte",
"(",
"text",
")",
",",
"1",
")",
"\n",
"htmlData",
"=",
"bytes",
".",
"Replace",
"(",
"htmlData",
",",
"[",
"]",
"byte",
"(",
"`{{ extratext }}`",
")",
",",
"[",
"]",
"byte",
"(",
"extratext",
")",
",",
"1",
")",
"\n",
"sessions",
".",
"Save",
"(",
"request",
",",
"w",
")",
"\n",
"w",
".",
"Write",
"(",
"htmlData",
")",
"\n",
"}"
] | //renderSMSConfirmationPage renders a small mobile friendly confirmation page after a user follows a link in an sms | [
"renderSMSConfirmationPage",
"renders",
"a",
"small",
"mobile",
"friendly",
"confirmation",
"page",
"after",
"a",
"user",
"follows",
"a",
"link",
"in",
"an",
"sms"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/service.go#L248-L259 |
13,854 | itsyouonline/identityserver | siteservice/registration.go | CheckRegistrationSMSConfirmation | func (service *Service) CheckRegistrationSMSConfirmation(w http.ResponseWriter, r *http.Request) {
registrationSession, err := service.GetSession(r, SessionForRegistration, "registrationdetails")
if err != nil {
log.Error(err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
response := map[string]bool{}
if registrationSession.IsNew {
// TODO: registrationSession is new with SMS, something must be wrong
log.Info("Registration session timed out while polling for phone confirmation")
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
return
}
sessionKey, _ := registrationSession.Values["sessionkey"].(string)
if sessionKey == "" {
log.Debug("Polling for sms confirmation without session key")
sessions.Save(r, w)
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
return
}
registeringUser, err := registration.NewManager(r).GetRegisteringUserBySessionKey(sessionKey)
if err != nil {
log.Error("Failed to load registering user object: ", err)
sessions.Save(r, w)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
confirmed, err := service.phonenumberValidationService.IsConfirmed(r, registeringUser.PhoneValidationKey)
if err == validation.ErrInvalidOrExpiredKey {
confirmed = true //This way the form will be submitted, let the form handler deal with redirect to login
return
}
if err != nil {
log.Error("Failed to check if phone is confirmed in registration flow: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
response["confirmed"] = confirmed
if confirmed {
persistentlog.NewManager(r).SaveLog(persistentlog.New(sessionKey, persistentlog.RegistrationFlow, "Users phone is confirmed"))
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(response)
} | go | func (service *Service) CheckRegistrationSMSConfirmation(w http.ResponseWriter, r *http.Request) {
registrationSession, err := service.GetSession(r, SessionForRegistration, "registrationdetails")
if err != nil {
log.Error(err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
response := map[string]bool{}
if registrationSession.IsNew {
// TODO: registrationSession is new with SMS, something must be wrong
log.Info("Registration session timed out while polling for phone confirmation")
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
return
}
sessionKey, _ := registrationSession.Values["sessionkey"].(string)
if sessionKey == "" {
log.Debug("Polling for sms confirmation without session key")
sessions.Save(r, w)
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
return
}
registeringUser, err := registration.NewManager(r).GetRegisteringUserBySessionKey(sessionKey)
if err != nil {
log.Error("Failed to load registering user object: ", err)
sessions.Save(r, w)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
confirmed, err := service.phonenumberValidationService.IsConfirmed(r, registeringUser.PhoneValidationKey)
if err == validation.ErrInvalidOrExpiredKey {
confirmed = true //This way the form will be submitted, let the form handler deal with redirect to login
return
}
if err != nil {
log.Error("Failed to check if phone is confirmed in registration flow: ", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
response["confirmed"] = confirmed
if confirmed {
persistentlog.NewManager(r).SaveLog(persistentlog.New(sessionKey, persistentlog.RegistrationFlow, "Users phone is confirmed"))
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(response)
} | [
"func",
"(",
"service",
"*",
"Service",
")",
"CheckRegistrationSMSConfirmation",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"registrationSession",
",",
"err",
":=",
"service",
".",
"GetSession",
"(",
"r",
",",
"SessionForRegistration",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n",
"response",
":=",
"map",
"[",
"string",
"]",
"bool",
"{",
"}",
"\n\n",
"if",
"registrationSession",
".",
"IsNew",
"{",
"// TODO: registrationSession is new with SMS, something must be wrong",
"log",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusUnauthorized",
")",
",",
"http",
".",
"StatusUnauthorized",
")",
"\n",
"return",
"\n",
"}",
"\n",
"sessionKey",
",",
"_",
":=",
"registrationSession",
".",
"Values",
"[",
"\"",
"\"",
"]",
".",
"(",
"string",
")",
"\n",
"if",
"sessionKey",
"==",
"\"",
"\"",
"{",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"sessions",
".",
"Save",
"(",
"r",
",",
"w",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusUnauthorized",
")",
",",
"http",
".",
"StatusUnauthorized",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"registeringUser",
",",
"err",
":=",
"registration",
".",
"NewManager",
"(",
"r",
")",
".",
"GetRegisteringUserBySessionKey",
"(",
"sessionKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"sessions",
".",
"Save",
"(",
"r",
",",
"w",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"confirmed",
",",
"err",
":=",
"service",
".",
"phonenumberValidationService",
".",
"IsConfirmed",
"(",
"r",
",",
"registeringUser",
".",
"PhoneValidationKey",
")",
"\n",
"if",
"err",
"==",
"validation",
".",
"ErrInvalidOrExpiredKey",
"{",
"confirmed",
"=",
"true",
"//This way the form will be submitted, let the form handler deal with redirect to login",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n",
"response",
"[",
"\"",
"\"",
"]",
"=",
"confirmed",
"\n\n",
"if",
"confirmed",
"{",
"persistentlog",
".",
"NewManager",
"(",
"r",
")",
".",
"SaveLog",
"(",
"persistentlog",
".",
"New",
"(",
"sessionKey",
",",
"persistentlog",
".",
"RegistrationFlow",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"json",
".",
"NewEncoder",
"(",
"w",
")",
".",
"Encode",
"(",
"response",
")",
"\n",
"}"
] | //CheckRegistrationSMSConfirmation is called by the sms code form to check if the sms is already confirmed on the mobile phone | [
"CheckRegistrationSMSConfirmation",
"is",
"called",
"by",
"the",
"sms",
"code",
"form",
"to",
"check",
"if",
"the",
"sms",
"is",
"already",
"confirmed",
"on",
"the",
"mobile",
"phone"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/registration.go#L45-L94 |
13,855 | itsyouonline/identityserver | siteservice/registration.go | ShowRegistrationForm | func (service *Service) ShowRegistrationForm(w http.ResponseWriter, request *http.Request) {
service.renderRegistrationFrom(w, request)
} | go | func (service *Service) ShowRegistrationForm(w http.ResponseWriter, request *http.Request) {
service.renderRegistrationFrom(w, request)
} | [
"func",
"(",
"service",
"*",
"Service",
")",
"ShowRegistrationForm",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"request",
"*",
"http",
".",
"Request",
")",
"{",
"service",
".",
"renderRegistrationFrom",
"(",
"w",
",",
"request",
")",
"\n",
"}"
] | //ShowRegistrationForm shows the user registration page | [
"ShowRegistrationForm",
"shows",
"the",
"user",
"registration",
"page"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/registration.go#L151-L153 |
13,856 | itsyouonline/identityserver | siteservice/registration.go | generateUsername | func generateUsername(r *http.Request, firstname, lastname string) (string, error) {
counter := 0
var username string
for _, r := range firstname {
if unicode.IsSpace(r) {
continue
}
username += string(unicode.ToLower(r))
}
username += "_"
for _, r := range lastname {
if unicode.IsSpace(r) {
continue
}
username += string(unicode.ToLower(r))
}
username += "_"
userMgr := user.NewManager(r)
count, err := userMgr.GetPendingRegistrationsCount()
if err != nil {
return "", err
}
log.Debug("count", count)
if count >= MAX_PENDING_REGISTRATION_COUNT {
return "", errors.New("Max amount of pending registrations reached")
}
orgMgr := organization.NewManager(r)
exists := true
for exists {
counter++
var err error
exists, err = userMgr.Exists(username + strconv.Itoa(counter))
if err != nil {
return "", err
}
if !exists {
exists = orgMgr.Exists(username + strconv.Itoa(counter))
}
}
username = username + strconv.Itoa(counter)
return username, nil
} | go | func generateUsername(r *http.Request, firstname, lastname string) (string, error) {
counter := 0
var username string
for _, r := range firstname {
if unicode.IsSpace(r) {
continue
}
username += string(unicode.ToLower(r))
}
username += "_"
for _, r := range lastname {
if unicode.IsSpace(r) {
continue
}
username += string(unicode.ToLower(r))
}
username += "_"
userMgr := user.NewManager(r)
count, err := userMgr.GetPendingRegistrationsCount()
if err != nil {
return "", err
}
log.Debug("count", count)
if count >= MAX_PENDING_REGISTRATION_COUNT {
return "", errors.New("Max amount of pending registrations reached")
}
orgMgr := organization.NewManager(r)
exists := true
for exists {
counter++
var err error
exists, err = userMgr.Exists(username + strconv.Itoa(counter))
if err != nil {
return "", err
}
if !exists {
exists = orgMgr.Exists(username + strconv.Itoa(counter))
}
}
username = username + strconv.Itoa(counter)
return username, nil
} | [
"func",
"generateUsername",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"firstname",
",",
"lastname",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"counter",
":=",
"0",
"\n",
"var",
"username",
"string",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"firstname",
"{",
"if",
"unicode",
".",
"IsSpace",
"(",
"r",
")",
"{",
"continue",
"\n",
"}",
"\n",
"username",
"+=",
"string",
"(",
"unicode",
".",
"ToLower",
"(",
"r",
")",
")",
"\n",
"}",
"\n",
"username",
"+=",
"\"",
"\"",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"lastname",
"{",
"if",
"unicode",
".",
"IsSpace",
"(",
"r",
")",
"{",
"continue",
"\n",
"}",
"\n",
"username",
"+=",
"string",
"(",
"unicode",
".",
"ToLower",
"(",
"r",
")",
")",
"\n",
"}",
"\n",
"username",
"+=",
"\"",
"\"",
"\n",
"userMgr",
":=",
"user",
".",
"NewManager",
"(",
"r",
")",
"\n\n",
"count",
",",
"err",
":=",
"userMgr",
".",
"GetPendingRegistrationsCount",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"count",
")",
"\n",
"if",
"count",
">=",
"MAX_PENDING_REGISTRATION_COUNT",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"orgMgr",
":=",
"organization",
".",
"NewManager",
"(",
"r",
")",
"\n",
"exists",
":=",
"true",
"\n",
"for",
"exists",
"{",
"counter",
"++",
"\n",
"var",
"err",
"error",
"\n",
"exists",
",",
"err",
"=",
"userMgr",
".",
"Exists",
"(",
"username",
"+",
"strconv",
".",
"Itoa",
"(",
"counter",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"!",
"exists",
"{",
"exists",
"=",
"orgMgr",
".",
"Exists",
"(",
"username",
"+",
"strconv",
".",
"Itoa",
"(",
"counter",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"username",
"=",
"username",
"+",
"strconv",
".",
"Itoa",
"(",
"counter",
")",
"\n",
"return",
"username",
",",
"nil",
"\n",
"}"
] | // generateUsername generates a new username | [
"generateUsername",
"generates",
"a",
"new",
"username"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/registration.go#L725-L768 |
13,857 | itsyouonline/identityserver | oauthservice/access_token.go | IsExpiredAt | func (at *AccessToken) IsExpiredAt(testtime time.Time) bool {
return testtime.After(at.ExpirationTime())
} | go | func (at *AccessToken) IsExpiredAt(testtime time.Time) bool {
return testtime.After(at.ExpirationTime())
} | [
"func",
"(",
"at",
"*",
"AccessToken",
")",
"IsExpiredAt",
"(",
"testtime",
"time",
".",
"Time",
")",
"bool",
"{",
"return",
"testtime",
".",
"After",
"(",
"at",
".",
"ExpirationTime",
"(",
")",
")",
"\n",
"}"
] | //IsExpiredAt checks if the token is expired at a specific time | [
"IsExpiredAt",
"checks",
"if",
"the",
"token",
"is",
"expired",
"at",
"a",
"specific",
"time"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/access_token.go#L34-L36 |
13,858 | itsyouonline/identityserver | db/grants/grant.go | Validate | func (grant *Grant) Validate() error {
g := string(*grant)
if len(g) > grantMaxLen {
return ErrGrantTooLarge
}
if len(g) < grantMinLen {
return ErrGrantTooSmall
}
if grantRegex.MatchString(g) {
return nil
}
return ErrInvalidGrantCharacter
} | go | func (grant *Grant) Validate() error {
g := string(*grant)
if len(g) > grantMaxLen {
return ErrGrantTooLarge
}
if len(g) < grantMinLen {
return ErrGrantTooSmall
}
if grantRegex.MatchString(g) {
return nil
}
return ErrInvalidGrantCharacter
} | [
"func",
"(",
"grant",
"*",
"Grant",
")",
"Validate",
"(",
")",
"error",
"{",
"g",
":=",
"string",
"(",
"*",
"grant",
")",
"\n",
"if",
"len",
"(",
"g",
")",
">",
"grantMaxLen",
"{",
"return",
"ErrGrantTooLarge",
"\n",
"}",
"\n",
"if",
"len",
"(",
"g",
")",
"<",
"grantMinLen",
"{",
"return",
"ErrGrantTooSmall",
"\n",
"}",
"\n\n",
"if",
"grantRegex",
".",
"MatchString",
"(",
"g",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"ErrInvalidGrantCharacter",
"\n",
"}"
] | // Validate validates a raw grant. Validation is successfull if the error is nil | [
"Validate",
"validates",
"a",
"raw",
"grant",
".",
"Validation",
"is",
"successfull",
"if",
"the",
"error",
"is",
"nil"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/grants/grant.go#L40-L53 |
13,859 | itsyouonline/identityserver | db/grants/grant.go | FullName | func FullName(grant Grant) string {
if strings.HasPrefix(string(grant), grantPrefix) {
return string(grant)
}
return grantPrefix + string(grant)
} | go | func FullName(grant Grant) string {
if strings.HasPrefix(string(grant), grantPrefix) {
return string(grant)
}
return grantPrefix + string(grant)
} | [
"func",
"FullName",
"(",
"grant",
"Grant",
")",
"string",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"string",
"(",
"grant",
")",
",",
"grantPrefix",
")",
"{",
"return",
"string",
"(",
"grant",
")",
"\n",
"}",
"\n",
"return",
"grantPrefix",
"+",
"string",
"(",
"grant",
")",
"\n",
"}"
] | // FullName ensures that a grant starts with the grantPrefix | [
"FullName",
"ensures",
"that",
"a",
"grant",
"starts",
"with",
"the",
"grantPrefix"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/grants/grant.go#L56-L61 |
13,860 | itsyouonline/identityserver | db/datetime.go | SetBSON | func (dt *DateTime) SetBSON(raw bson.Raw) error {
decoded := time.Time{}
bsonErr := raw.Unmarshal(&decoded)
if bsonErr != nil {
return bsonErr
}
*dt = DateTime(decoded)
return nil
} | go | func (dt *DateTime) SetBSON(raw bson.Raw) error {
decoded := time.Time{}
bsonErr := raw.Unmarshal(&decoded)
if bsonErr != nil {
return bsonErr
}
*dt = DateTime(decoded)
return nil
} | [
"func",
"(",
"dt",
"*",
"DateTime",
")",
"SetBSON",
"(",
"raw",
"bson",
".",
"Raw",
")",
"error",
"{",
"decoded",
":=",
"time",
".",
"Time",
"{",
"}",
"\n\n",
"bsonErr",
":=",
"raw",
".",
"Unmarshal",
"(",
"&",
"decoded",
")",
"\n",
"if",
"bsonErr",
"!=",
"nil",
"{",
"return",
"bsonErr",
"\n",
"}",
"\n",
"*",
"dt",
"=",
"DateTime",
"(",
"decoded",
")",
"\n",
"return",
"nil",
"\n\n",
"}"
] | // SetBSON implements bson.Setter since the bson library does not look at underlying types and matches directly the time.Time type | [
"SetBSON",
"implements",
"bson",
".",
"Setter",
"since",
"the",
"bson",
"library",
"does",
"not",
"look",
"at",
"underlying",
"types",
"and",
"matches",
"directly",
"the",
"time",
".",
"Time",
"type"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/datetime.go#L44-L54 |
13,861 | itsyouonline/identityserver | clients/go/itsyouonline/organizations_service.go | UpdateOrganizationAPIKey | func (s *OrganizationsService) UpdateOrganizationAPIKey(label, globalid string, body OrganizationsGlobalidApikeysLabelPutReqBody, headers, queryParams map[string]interface{}) (*http.Response, error) {
var err error
resp, err := s.client.doReqWithBody("PUT", s.client.BaseURI+"/organizations/"+globalid+"/apikeys/"+label, &body, headers, queryParams)
if err != nil {
return nil, err
}
defer resp.Body.Close()
return resp, err
} | go | func (s *OrganizationsService) UpdateOrganizationAPIKey(label, globalid string, body OrganizationsGlobalidApikeysLabelPutReqBody, headers, queryParams map[string]interface{}) (*http.Response, error) {
var err error
resp, err := s.client.doReqWithBody("PUT", s.client.BaseURI+"/organizations/"+globalid+"/apikeys/"+label, &body, headers, queryParams)
if err != nil {
return nil, err
}
defer resp.Body.Close()
return resp, err
} | [
"func",
"(",
"s",
"*",
"OrganizationsService",
")",
"UpdateOrganizationAPIKey",
"(",
"label",
",",
"globalid",
"string",
",",
"body",
"OrganizationsGlobalidApikeysLabelPutReqBody",
",",
"headers",
",",
"queryParams",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"resp",
",",
"err",
":=",
"s",
".",
"client",
".",
"doReqWithBody",
"(",
"\"",
"\"",
",",
"s",
".",
"client",
".",
"BaseURI",
"+",
"\"",
"\"",
"+",
"globalid",
"+",
"\"",
"\"",
"+",
"label",
",",
"&",
"body",
",",
"headers",
",",
"queryParams",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"return",
"resp",
",",
"err",
"\n",
"}"
] | // Updates the label or other properties of a key. | [
"Updates",
"the",
"label",
"or",
"other",
"properties",
"of",
"a",
"key",
"."
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/clients/go/itsyouonline/organizations_service.go#L81-L91 |
13,862 | itsyouonline/identityserver | clients/go/itsyouonline/organizations_service.go | UpdateOrganizationDns | func (s *OrganizationsService) UpdateOrganizationDns(dnsname, globalid string, body DnsAddress, headers, queryParams map[string]interface{}) (*http.Response, error) {
var err error
resp, err := s.client.doReqWithBody("PUT", s.client.BaseURI+"/organizations/"+globalid+"/dns/"+dnsname, &body, headers, queryParams)
if err != nil {
return nil, err
}
defer resp.Body.Close()
return resp, err
} | go | func (s *OrganizationsService) UpdateOrganizationDns(dnsname, globalid string, body DnsAddress, headers, queryParams map[string]interface{}) (*http.Response, error) {
var err error
resp, err := s.client.doReqWithBody("PUT", s.client.BaseURI+"/organizations/"+globalid+"/dns/"+dnsname, &body, headers, queryParams)
if err != nil {
return nil, err
}
defer resp.Body.Close()
return resp, err
} | [
"func",
"(",
"s",
"*",
"OrganizationsService",
")",
"UpdateOrganizationDns",
"(",
"dnsname",
",",
"globalid",
"string",
",",
"body",
"DnsAddress",
",",
"headers",
",",
"queryParams",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"resp",
",",
"err",
":=",
"s",
".",
"client",
".",
"doReqWithBody",
"(",
"\"",
"\"",
",",
"s",
".",
"client",
".",
"BaseURI",
"+",
"\"",
"\"",
"+",
"globalid",
"+",
"\"",
"\"",
"+",
"dnsname",
",",
"&",
"body",
",",
"headers",
",",
"queryParams",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"return",
"resp",
",",
"err",
"\n",
"}"
] | // Updates an existing DNS name associated with an organization | [
"Updates",
"an",
"existing",
"DNS",
"name",
"associated",
"with",
"an",
"organization"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/clients/go/itsyouonline/organizations_service.go#L280-L290 |
13,863 | itsyouonline/identityserver | clients/go/itsyouonline/organizations_service.go | RejectOrganizationInvite | func (s *OrganizationsService) RejectOrganizationInvite(invitingorg, role, globalid string, headers, queryParams map[string]interface{}) (*http.Response, error) {
var err error
resp, err := s.client.doReqNoBody("DELETE", s.client.BaseURI+"/organizations/"+globalid+"/organizations/"+invitingorg+"/roles/"+role, headers, queryParams)
if err != nil {
return nil, err
}
defer resp.Body.Close()
return resp, err
} | go | func (s *OrganizationsService) RejectOrganizationInvite(invitingorg, role, globalid string, headers, queryParams map[string]interface{}) (*http.Response, error) {
var err error
resp, err := s.client.doReqNoBody("DELETE", s.client.BaseURI+"/organizations/"+globalid+"/organizations/"+invitingorg+"/roles/"+role, headers, queryParams)
if err != nil {
return nil, err
}
defer resp.Body.Close()
return resp, err
} | [
"func",
"(",
"s",
"*",
"OrganizationsService",
")",
"RejectOrganizationInvite",
"(",
"invitingorg",
",",
"role",
",",
"globalid",
"string",
",",
"headers",
",",
"queryParams",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"resp",
",",
"err",
":=",
"s",
".",
"client",
".",
"doReqNoBody",
"(",
"\"",
"\"",
",",
"s",
".",
"client",
".",
"BaseURI",
"+",
"\"",
"\"",
"+",
"globalid",
"+",
"\"",
"\"",
"+",
"invitingorg",
"+",
"\"",
"\"",
"+",
"role",
",",
"headers",
",",
"queryParams",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"return",
"resp",
",",
"err",
"\n",
"}"
] | // Reject the invite for one of your organizations | [
"Reject",
"the",
"invite",
"for",
"one",
"of",
"your",
"organizations"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/clients/go/itsyouonline/organizations_service.go#L571-L581 |
13,864 | itsyouonline/identityserver | clients/go/itsyouonline/organizations_service.go | SetOrgOwner | func (s *OrganizationsService) SetOrgOwner(globalid string, body OrganizationsGlobalidOrgownersPostReqBody, headers, queryParams map[string]interface{}) (*http.Response, error) {
var err error
resp, err := s.client.doReqWithBody("POST", s.client.BaseURI+"/organizations/"+globalid+"/orgowners", &body, headers, queryParams)
if err != nil {
return nil, err
}
defer resp.Body.Close()
return resp, err
} | go | func (s *OrganizationsService) SetOrgOwner(globalid string, body OrganizationsGlobalidOrgownersPostReqBody, headers, queryParams map[string]interface{}) (*http.Response, error) {
var err error
resp, err := s.client.doReqWithBody("POST", s.client.BaseURI+"/organizations/"+globalid+"/orgowners", &body, headers, queryParams)
if err != nil {
return nil, err
}
defer resp.Body.Close()
return resp, err
} | [
"func",
"(",
"s",
"*",
"OrganizationsService",
")",
"SetOrgOwner",
"(",
"globalid",
"string",
",",
"body",
"OrganizationsGlobalidOrgownersPostReqBody",
",",
"headers",
",",
"queryParams",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"resp",
",",
"err",
":=",
"s",
".",
"client",
".",
"doReqWithBody",
"(",
"\"",
"\"",
",",
"s",
".",
"client",
".",
"BaseURI",
"+",
"\"",
"\"",
"+",
"globalid",
"+",
"\"",
"\"",
",",
"&",
"body",
",",
"headers",
",",
"queryParams",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"return",
"resp",
",",
"err",
"\n",
"}"
] | // Add another organization as an owner of this one | [
"Add",
"another",
"organization",
"as",
"an",
"owner",
"of",
"this",
"one"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/clients/go/itsyouonline/organizations_service.go#L699-L709 |
13,865 | itsyouonline/identityserver | db/registration/InProgressRegistration.go | New | func New(sessionKey string) *InProgressRegistration {
return &InProgressRegistration{
CreatedAt: time.Now(),
SessionKey: sessionKey,
}
} | go | func New(sessionKey string) *InProgressRegistration {
return &InProgressRegistration{
CreatedAt: time.Now(),
SessionKey: sessionKey,
}
} | [
"func",
"New",
"(",
"sessionKey",
"string",
")",
"*",
"InProgressRegistration",
"{",
"return",
"&",
"InProgressRegistration",
"{",
"CreatedAt",
":",
"time",
".",
"Now",
"(",
")",
",",
"SessionKey",
":",
"sessionKey",
",",
"}",
"\n",
"}"
] | // New returns a new in progress registration object | [
"New",
"returns",
"a",
"new",
"in",
"progress",
"registration",
"object"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/registration/InProgressRegistration.go#L20-L25 |
13,866 | itsyouonline/identityserver | db/registry/db.go | DeleteRegistryEntry | func (m *Manager) DeleteRegistryEntry(username string, globalid string, key string) (err error) {
selector, err := createSelector(username, globalid, key)
if err != nil {
return
}
_, err = m.getRegistryCollection().UpdateAll(
selector,
bson.M{"$pull": bson.M{"entries": bson.M{"key": key}}})
return
} | go | func (m *Manager) DeleteRegistryEntry(username string, globalid string, key string) (err error) {
selector, err := createSelector(username, globalid, key)
if err != nil {
return
}
_, err = m.getRegistryCollection().UpdateAll(
selector,
bson.M{"$pull": bson.M{"entries": bson.M{"key": key}}})
return
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"DeleteRegistryEntry",
"(",
"username",
"string",
",",
"globalid",
"string",
",",
"key",
"string",
")",
"(",
"err",
"error",
")",
"{",
"selector",
",",
"err",
":=",
"createSelector",
"(",
"username",
",",
"globalid",
",",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"m",
".",
"getRegistryCollection",
"(",
")",
".",
"UpdateAll",
"(",
"selector",
",",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"key",
"}",
"}",
"}",
")",
"\n\n",
"return",
"\n",
"}"
] | //DeleteRegistryEntry deletes a registry entry
// Either a username or a globalid needs to be given
// If the key does not exist, no error is returned | [
"DeleteRegistryEntry",
"deletes",
"a",
"registry",
"entry",
"Either",
"a",
"username",
"or",
"a",
"globalid",
"needs",
"to",
"be",
"given",
"If",
"the",
"key",
"does",
"not",
"exist",
"no",
"error",
"is",
"returned"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/registry/db.go#L91-L102 |
13,867 | itsyouonline/identityserver | db/registry/db.go | UpsertRegistryEntry | func (m *Manager) UpsertRegistryEntry(username string, globalid string, registryEntry RegistryEntry) (err error) {
selector, err := createSelector(username, globalid, registryEntry.Key)
if err != nil {
return
}
result, err := m.getRegistryCollection().UpdateAll(selector, bson.M{"$set": bson.M{"entries.$.value": registryEntry.Value}})
if err == nil && result.Updated == 0 {
//Negate the selector on push so it is never pushed twice
if username != "" {
selector = bson.M{"username": username, "entries.key": bson.M{"$ne": registryEntry.Key}}
} else {
selector = bson.M{"globalid": globalid, "entries.key": bson.M{"$ne": registryEntry.Key}}
}
_, err = m.getRegistryCollection().Upsert(selector, bson.M{"$push": bson.M{"entries": ®istryEntry}})
}
return
} | go | func (m *Manager) UpsertRegistryEntry(username string, globalid string, registryEntry RegistryEntry) (err error) {
selector, err := createSelector(username, globalid, registryEntry.Key)
if err != nil {
return
}
result, err := m.getRegistryCollection().UpdateAll(selector, bson.M{"$set": bson.M{"entries.$.value": registryEntry.Value}})
if err == nil && result.Updated == 0 {
//Negate the selector on push so it is never pushed twice
if username != "" {
selector = bson.M{"username": username, "entries.key": bson.M{"$ne": registryEntry.Key}}
} else {
selector = bson.M{"globalid": globalid, "entries.key": bson.M{"$ne": registryEntry.Key}}
}
_, err = m.getRegistryCollection().Upsert(selector, bson.M{"$push": bson.M{"entries": ®istryEntry}})
}
return
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"UpsertRegistryEntry",
"(",
"username",
"string",
",",
"globalid",
"string",
",",
"registryEntry",
"RegistryEntry",
")",
"(",
"err",
"error",
")",
"{",
"selector",
",",
"err",
":=",
"createSelector",
"(",
"username",
",",
"globalid",
",",
"registryEntry",
".",
"Key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"result",
",",
"err",
":=",
"m",
".",
"getRegistryCollection",
"(",
")",
".",
"UpdateAll",
"(",
"selector",
",",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"registryEntry",
".",
"Value",
"}",
"}",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"result",
".",
"Updated",
"==",
"0",
"{",
"//Negate the selector on push so it is never pushed twice",
"if",
"username",
"!=",
"\"",
"\"",
"{",
"selector",
"=",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"username",
",",
"\"",
"\"",
":",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"registryEntry",
".",
"Key",
"}",
"}",
"\n",
"}",
"else",
"{",
"selector",
"=",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"globalid",
",",
"\"",
"\"",
":",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"registryEntry",
".",
"Key",
"}",
"}",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"m",
".",
"getRegistryCollection",
"(",
")",
".",
"Upsert",
"(",
"selector",
",",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"&",
"registryEntry",
"}",
"}",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | //UpsertRegistryEntry updates or inserts a registry entry
// Either a username or a globalid needs to be given | [
"UpsertRegistryEntry",
"updates",
"or",
"inserts",
"a",
"registry",
"entry",
"Either",
"a",
"username",
"or",
"a",
"globalid",
"needs",
"to",
"be",
"given"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/registry/db.go#L106-L122 |
13,868 | itsyouonline/identityserver | db/registry/db.go | ListRegistryEntries | func (m *Manager) ListRegistryEntries(username string, globalid string) (registryEntries []RegistryEntry, err error) {
var selector bson.M
if username != "" {
selector = bson.M{"username": username}
} else {
selector = bson.M{"globalid": globalid}
}
result := struct {
Entries []RegistryEntry
}{}
err = m.getRegistryCollection().Find(selector).Select(bson.M{"entries": 1}).One(&result)
if err == mgo.ErrNotFound {
err = nil
registryEntries = []RegistryEntry{}
return
}
registryEntries = result.Entries
return
} | go | func (m *Manager) ListRegistryEntries(username string, globalid string) (registryEntries []RegistryEntry, err error) {
var selector bson.M
if username != "" {
selector = bson.M{"username": username}
} else {
selector = bson.M{"globalid": globalid}
}
result := struct {
Entries []RegistryEntry
}{}
err = m.getRegistryCollection().Find(selector).Select(bson.M{"entries": 1}).One(&result)
if err == mgo.ErrNotFound {
err = nil
registryEntries = []RegistryEntry{}
return
}
registryEntries = result.Entries
return
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"ListRegistryEntries",
"(",
"username",
"string",
",",
"globalid",
"string",
")",
"(",
"registryEntries",
"[",
"]",
"RegistryEntry",
",",
"err",
"error",
")",
"{",
"var",
"selector",
"bson",
".",
"M",
"\n",
"if",
"username",
"!=",
"\"",
"\"",
"{",
"selector",
"=",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"username",
"}",
"\n",
"}",
"else",
"{",
"selector",
"=",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"globalid",
"}",
"\n",
"}",
"\n",
"result",
":=",
"struct",
"{",
"Entries",
"[",
"]",
"RegistryEntry",
"\n",
"}",
"{",
"}",
"\n",
"err",
"=",
"m",
".",
"getRegistryCollection",
"(",
")",
".",
"Find",
"(",
"selector",
")",
".",
"Select",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"1",
"}",
")",
".",
"One",
"(",
"&",
"result",
")",
"\n",
"if",
"err",
"==",
"mgo",
".",
"ErrNotFound",
"{",
"err",
"=",
"nil",
"\n",
"registryEntries",
"=",
"[",
"]",
"RegistryEntry",
"{",
"}",
"\n",
"return",
"\n",
"}",
"\n",
"registryEntries",
"=",
"result",
".",
"Entries",
"\n",
"return",
"\n",
"}"
] | //ListRegistryEntries gets all registry entries for a user or organization | [
"ListRegistryEntries",
"gets",
"all",
"registry",
"entries",
"for",
"a",
"user",
"or",
"organization"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/registry/db.go#L125-L143 |
13,869 | itsyouonline/identityserver | db/registry/db.go | GetRegistryEntry | func (m *Manager) GetRegistryEntry(username string, globalid string, key string) (registryEntry *RegistryEntry, err error) {
selector, err := createSelector(username, globalid, key)
result := struct {
Entries []RegistryEntry
}{}
err = m.getRegistryCollection().Find(selector).Select(bson.M{"entries.$": 1}).One(&result)
if err == mgo.ErrNotFound {
err = nil
return
}
if result.Entries != nil && len(result.Entries) > 0 {
registryEntry = &result.Entries[0]
}
return
} | go | func (m *Manager) GetRegistryEntry(username string, globalid string, key string) (registryEntry *RegistryEntry, err error) {
selector, err := createSelector(username, globalid, key)
result := struct {
Entries []RegistryEntry
}{}
err = m.getRegistryCollection().Find(selector).Select(bson.M{"entries.$": 1}).One(&result)
if err == mgo.ErrNotFound {
err = nil
return
}
if result.Entries != nil && len(result.Entries) > 0 {
registryEntry = &result.Entries[0]
}
return
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"GetRegistryEntry",
"(",
"username",
"string",
",",
"globalid",
"string",
",",
"key",
"string",
")",
"(",
"registryEntry",
"*",
"RegistryEntry",
",",
"err",
"error",
")",
"{",
"selector",
",",
"err",
":=",
"createSelector",
"(",
"username",
",",
"globalid",
",",
"key",
")",
"\n",
"result",
":=",
"struct",
"{",
"Entries",
"[",
"]",
"RegistryEntry",
"\n",
"}",
"{",
"}",
"\n",
"err",
"=",
"m",
".",
"getRegistryCollection",
"(",
")",
".",
"Find",
"(",
"selector",
")",
".",
"Select",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"1",
"}",
")",
".",
"One",
"(",
"&",
"result",
")",
"\n",
"if",
"err",
"==",
"mgo",
".",
"ErrNotFound",
"{",
"err",
"=",
"nil",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"result",
".",
"Entries",
"!=",
"nil",
"&&",
"len",
"(",
"result",
".",
"Entries",
")",
">",
"0",
"{",
"registryEntry",
"=",
"&",
"result",
".",
"Entries",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"\n\n",
"}"
] | // GetRegistryEntry gets a registryentry for a user or organization
// If no such entry exists, nil is returned, both for the registryEntry and error | [
"GetRegistryEntry",
"gets",
"a",
"registryentry",
"for",
"a",
"user",
"or",
"organization",
"If",
"no",
"such",
"entry",
"exists",
"nil",
"is",
"returned",
"both",
"for",
"the",
"registryEntry",
"and",
"error"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/registry/db.go#L147-L162 |
13,870 | itsyouonline/identityserver | db/iyoid/db.go | GetByUsernameAndAZP | func (m *Manager) GetByUsernameAndAZP(username, azp string) (*Identifier, error) {
var idObj Identifier
if err := m.getIdentifierCollection().Find(bson.M{"username": username, "azp": azp}).One(&idObj); err != nil {
return nil, err
}
return &idObj, nil
} | go | func (m *Manager) GetByUsernameAndAZP(username, azp string) (*Identifier, error) {
var idObj Identifier
if err := m.getIdentifierCollection().Find(bson.M{"username": username, "azp": azp}).One(&idObj); err != nil {
return nil, err
}
return &idObj, nil
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"GetByUsernameAndAZP",
"(",
"username",
",",
"azp",
"string",
")",
"(",
"*",
"Identifier",
",",
"error",
")",
"{",
"var",
"idObj",
"Identifier",
"\n\n",
"if",
"err",
":=",
"m",
".",
"getIdentifierCollection",
"(",
")",
".",
"Find",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"username",
",",
"\"",
"\"",
":",
"azp",
"}",
")",
".",
"One",
"(",
"&",
"idObj",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"idObj",
",",
"nil",
"\n",
"}"
] | // GetByUsernameAndAZP returns the Identifier object for this username and azp combo | [
"GetByUsernameAndAZP",
"returns",
"the",
"Identifier",
"object",
"for",
"this",
"username",
"and",
"azp",
"combo"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/iyoid/db.go#L75-L83 |
13,871 | itsyouonline/identityserver | db/iyoid/db.go | GetByID | func (m *Manager) GetByID(iyoid string) (*Identifier, error) {
var idObj Identifier
if err := m.getIdentifierCollection().Find(bson.M{"iyoids": iyoid}).One(&idObj); err != nil {
return nil, err
}
return &idObj, nil
} | go | func (m *Manager) GetByID(iyoid string) (*Identifier, error) {
var idObj Identifier
if err := m.getIdentifierCollection().Find(bson.M{"iyoids": iyoid}).One(&idObj); err != nil {
return nil, err
}
return &idObj, nil
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"GetByID",
"(",
"iyoid",
"string",
")",
"(",
"*",
"Identifier",
",",
"error",
")",
"{",
"var",
"idObj",
"Identifier",
"\n\n",
"if",
"err",
":=",
"m",
".",
"getIdentifierCollection",
"(",
")",
".",
"Find",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"iyoid",
"}",
")",
".",
"One",
"(",
"&",
"idObj",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"idObj",
",",
"nil",
"\n",
"}"
] | // GetByID returns the full identifier object for this iyoid | [
"GetByID",
"returns",
"the",
"full",
"identifier",
"object",
"for",
"this",
"iyoid"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/iyoid/db.go#L86-L94 |
13,872 | itsyouonline/identityserver | db/iyoid/db.go | UpsertIdentifier | func (m *Manager) UpsertIdentifier(username, azp, iyoid string) error {
// Count the amount of iyoids we already have first
idObj, err := m.GetByUsernameAndAZP(username, azp)
if err != nil && !db.IsNotFound(err) {
return err
}
if db.IsNotFound(err) {
idObj = &Identifier{}
}
if len(idObj.IyoIDs) >= maxIdentifiers {
return ErrIDLimitReached
}
_, err = m.getIdentifierCollection().Upsert(bson.M{"username": username, "azp": azp}, bson.M{"$push": bson.M{"iyoids": iyoid}})
return err
} | go | func (m *Manager) UpsertIdentifier(username, azp, iyoid string) error {
// Count the amount of iyoids we already have first
idObj, err := m.GetByUsernameAndAZP(username, azp)
if err != nil && !db.IsNotFound(err) {
return err
}
if db.IsNotFound(err) {
idObj = &Identifier{}
}
if len(idObj.IyoIDs) >= maxIdentifiers {
return ErrIDLimitReached
}
_, err = m.getIdentifierCollection().Upsert(bson.M{"username": username, "azp": azp}, bson.M{"$push": bson.M{"iyoids": iyoid}})
return err
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"UpsertIdentifier",
"(",
"username",
",",
"azp",
",",
"iyoid",
"string",
")",
"error",
"{",
"// Count the amount of iyoids we already have first",
"idObj",
",",
"err",
":=",
"m",
".",
"GetByUsernameAndAZP",
"(",
"username",
",",
"azp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"db",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"db",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"idObj",
"=",
"&",
"Identifier",
"{",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"idObj",
".",
"IyoIDs",
")",
">=",
"maxIdentifiers",
"{",
"return",
"ErrIDLimitReached",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"m",
".",
"getIdentifierCollection",
"(",
")",
".",
"Upsert",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"username",
",",
"\"",
"\"",
":",
"azp",
"}",
",",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"iyoid",
"}",
"}",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // UpsertIdentifier adds a new iyoid to a mapping or creates a new mapping | [
"UpsertIdentifier",
"adds",
"a",
"new",
"iyoid",
"to",
"a",
"mapping",
"or",
"creates",
"a",
"new",
"mapping"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/iyoid/db.go#L97-L112 |
13,873 | itsyouonline/identityserver | db/iyoid/db.go | DeleteForClient | func (m *Manager) DeleteForClient(azp string) error {
_, err := m.getIdentifierCollection().RemoveAll(bson.M{"azp": azp})
return err
} | go | func (m *Manager) DeleteForClient(azp string) error {
_, err := m.getIdentifierCollection().RemoveAll(bson.M{"azp": azp})
return err
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"DeleteForClient",
"(",
"azp",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"m",
".",
"getIdentifierCollection",
"(",
")",
".",
"RemoveAll",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"azp",
"}",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // DeleteForClient deletes all iyoids for a client id | [
"DeleteForClient",
"deletes",
"all",
"iyoids",
"for",
"a",
"client",
"id"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/iyoid/db.go#L115-L118 |
13,874 | itsyouonline/identityserver | clients/go/itsyouonline/oauth.go | CreateJWTToken | func (c *Itsyouonline) CreateJWTToken(scopes, auds []string) (string, error) {
// build request
url := strings.TrimSuffix(c.BaseURI, "/api")
req, err := http.NewRequest("GET", url+"/v1/oauth/jwt", nil)
if err != nil {
return "", err
}
// set auth header
if c.AuthHeader == "" {
return "", fmt.Errorf("you need to create an oauth token in order to create JWT token")
}
req.Header.Set("Authorization", c.AuthHeader)
// query params
q := req.URL.Query()
if len(scopes) > 0 {
q.Add("scope", strings.Join(scopes, ","))
}
if len(auds) > 0 {
q.Add("aud", strings.Join(auds, ","))
}
req.URL.RawQuery = q.Encode()
// do the request
rsp, err := c.client.Do(req)
if err != nil {
return "", err
}
defer rsp.Body.Close()
if rsp.StatusCode != 200 {
return "", fmt.Errorf("invalid response's status code :%v", rsp.StatusCode)
}
b, err := ioutil.ReadAll(rsp.Body)
if err != nil {
return "", err
}
return string(b), nil
} | go | func (c *Itsyouonline) CreateJWTToken(scopes, auds []string) (string, error) {
// build request
url := strings.TrimSuffix(c.BaseURI, "/api")
req, err := http.NewRequest("GET", url+"/v1/oauth/jwt", nil)
if err != nil {
return "", err
}
// set auth header
if c.AuthHeader == "" {
return "", fmt.Errorf("you need to create an oauth token in order to create JWT token")
}
req.Header.Set("Authorization", c.AuthHeader)
// query params
q := req.URL.Query()
if len(scopes) > 0 {
q.Add("scope", strings.Join(scopes, ","))
}
if len(auds) > 0 {
q.Add("aud", strings.Join(auds, ","))
}
req.URL.RawQuery = q.Encode()
// do the request
rsp, err := c.client.Do(req)
if err != nil {
return "", err
}
defer rsp.Body.Close()
if rsp.StatusCode != 200 {
return "", fmt.Errorf("invalid response's status code :%v", rsp.StatusCode)
}
b, err := ioutil.ReadAll(rsp.Body)
if err != nil {
return "", err
}
return string(b), nil
} | [
"func",
"(",
"c",
"*",
"Itsyouonline",
")",
"CreateJWTToken",
"(",
"scopes",
",",
"auds",
"[",
"]",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"// build request",
"url",
":=",
"strings",
".",
"TrimSuffix",
"(",
"c",
".",
"BaseURI",
",",
"\"",
"\"",
")",
"\n",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"url",
"+",
"\"",
"\"",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"// set auth header",
"if",
"c",
".",
"AuthHeader",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"c",
".",
"AuthHeader",
")",
"\n\n",
"// query params",
"q",
":=",
"req",
".",
"URL",
".",
"Query",
"(",
")",
"\n",
"if",
"len",
"(",
"scopes",
")",
">",
"0",
"{",
"q",
".",
"Add",
"(",
"\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"scopes",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"auds",
")",
">",
"0",
"{",
"q",
".",
"Add",
"(",
"\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"auds",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"req",
".",
"URL",
".",
"RawQuery",
"=",
"q",
".",
"Encode",
"(",
")",
"\n\n",
"// do the request",
"rsp",
",",
"err",
":=",
"c",
".",
"client",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"defer",
"rsp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"if",
"rsp",
".",
"StatusCode",
"!=",
"200",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"rsp",
".",
"StatusCode",
")",
"\n",
"}",
"\n\n",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"rsp",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"string",
"(",
"b",
")",
",",
"nil",
"\n",
"}"
] | // CreateJWTToken creates JWT token with scope=scopes
// and audience=auds.
// To execute it, client need to be logged in. | [
"CreateJWTToken",
"creates",
"JWT",
"token",
"with",
"scope",
"=",
"scopes",
"and",
"audience",
"=",
"auds",
".",
"To",
"execute",
"it",
"client",
"need",
"to",
"be",
"logged",
"in",
"."
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/clients/go/itsyouonline/oauth.go#L82-L123 |
13,875 | itsyouonline/identityserver | db/registration/db.go | UpsertRegisteringUser | func (m *Manager) UpsertRegisteringUser(ipr *InProgressRegistration) error {
selector := bson.M{"sessionkey": ipr.SessionKey}
_, err := m.collection.Upsert(selector, ipr)
return err
} | go | func (m *Manager) UpsertRegisteringUser(ipr *InProgressRegistration) error {
selector := bson.M{"sessionkey": ipr.SessionKey}
_, err := m.collection.Upsert(selector, ipr)
return err
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"UpsertRegisteringUser",
"(",
"ipr",
"*",
"InProgressRegistration",
")",
"error",
"{",
"selector",
":=",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"ipr",
".",
"SessionKey",
"}",
"\n",
"_",
",",
"err",
":=",
"m",
".",
"collection",
".",
"Upsert",
"(",
"selector",
",",
"ipr",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // UpsertRegisteringUser creates a new or updates an existing entry in the db for a user currenly registering | [
"UpsertRegisteringUser",
"creates",
"a",
"new",
"or",
"updates",
"an",
"existing",
"entry",
"in",
"the",
"db",
"for",
"a",
"user",
"currenly",
"registering"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/registration/db.go#L64-L68 |
13,876 | itsyouonline/identityserver | db/registration/db.go | GetRegisteringUserBySessionKey | func (m *Manager) GetRegisteringUserBySessionKey(sessionKey string) (*InProgressRegistration, error) {
var ipr InProgressRegistration
err := m.collection.Find(bson.M{"sessionkey": sessionKey}).One(&ipr)
return &ipr, err
} | go | func (m *Manager) GetRegisteringUserBySessionKey(sessionKey string) (*InProgressRegistration, error) {
var ipr InProgressRegistration
err := m.collection.Find(bson.M{"sessionkey": sessionKey}).One(&ipr)
return &ipr, err
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"GetRegisteringUserBySessionKey",
"(",
"sessionKey",
"string",
")",
"(",
"*",
"InProgressRegistration",
",",
"error",
")",
"{",
"var",
"ipr",
"InProgressRegistration",
"\n\n",
"err",
":=",
"m",
".",
"collection",
".",
"Find",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"sessionKey",
"}",
")",
".",
"One",
"(",
"&",
"ipr",
")",
"\n\n",
"return",
"&",
"ipr",
",",
"err",
"\n",
"}"
] | // GetRegisteringUserBySessionKey returns a user object of an in progress registration | [
"GetRegisteringUserBySessionKey",
"returns",
"a",
"user",
"object",
"of",
"an",
"in",
"progress",
"registration"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/registration/db.go#L71-L77 |
13,877 | itsyouonline/identityserver | db/registration/db.go | DeleteRegisteringUser | func (m *Manager) DeleteRegisteringUser(sessionKey string) error {
return m.collection.Remove(bson.M{"sessionkey": sessionKey})
} | go | func (m *Manager) DeleteRegisteringUser(sessionKey string) error {
return m.collection.Remove(bson.M{"sessionkey": sessionKey})
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"DeleteRegisteringUser",
"(",
"sessionKey",
"string",
")",
"error",
"{",
"return",
"m",
".",
"collection",
".",
"Remove",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"sessionKey",
"}",
")",
"\n",
"}"
] | // DeleteRegisteringUser deletes a registering user | [
"DeleteRegisteringUser",
"deletes",
"a",
"registering",
"user"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/registration/db.go#L80-L82 |
13,878 | itsyouonline/identityserver | oauthservice/db.go | getAuthorizationRequestCollection | func (m *Manager) getAuthorizationRequestCollection() *mgo.Collection {
return db.GetCollection(m.session, requestsCollectionName)
} | go | func (m *Manager) getAuthorizationRequestCollection() *mgo.Collection {
return db.GetCollection(m.session, requestsCollectionName)
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"getAuthorizationRequestCollection",
"(",
")",
"*",
"mgo",
".",
"Collection",
"{",
"return",
"db",
".",
"GetCollection",
"(",
"m",
".",
"session",
",",
"requestsCollectionName",
")",
"\n",
"}"
] | //getAuthorizationRequestCollection returns the mongo collection for the authorizationRequests | [
"getAuthorizationRequestCollection",
"returns",
"the",
"mongo",
"collection",
"for",
"the",
"authorizationRequests"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/db.go#L97-L99 |
13,879 | itsyouonline/identityserver | oauthservice/db.go | getAccessTokenCollection | func (m *Manager) getAccessTokenCollection() *mgo.Collection {
return db.GetCollection(m.session, tokensCollectionName)
} | go | func (m *Manager) getAccessTokenCollection() *mgo.Collection {
return db.GetCollection(m.session, tokensCollectionName)
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"getAccessTokenCollection",
"(",
")",
"*",
"mgo",
".",
"Collection",
"{",
"return",
"db",
".",
"GetCollection",
"(",
"m",
".",
"session",
",",
"tokensCollectionName",
")",
"\n",
"}"
] | //getAccessTokenCollection returns the mongo collection for the accessTokens | [
"getAccessTokenCollection",
"returns",
"the",
"mongo",
"collection",
"for",
"the",
"accessTokens"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/db.go#L102-L104 |
13,880 | itsyouonline/identityserver | oauthservice/db.go | getRefreshTokenCollection | func (m *Manager) getRefreshTokenCollection() *mgo.Collection {
return db.GetCollection(m.session, refreshTokenCollectionName)
} | go | func (m *Manager) getRefreshTokenCollection() *mgo.Collection {
return db.GetCollection(m.session, refreshTokenCollectionName)
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"getRefreshTokenCollection",
"(",
")",
"*",
"mgo",
".",
"Collection",
"{",
"return",
"db",
".",
"GetCollection",
"(",
"m",
".",
"session",
",",
"refreshTokenCollectionName",
")",
"\n",
"}"
] | //getRefreshTokenCollection returns the mongo collection for the accessTokens | [
"getRefreshTokenCollection",
"returns",
"the",
"mongo",
"collection",
"for",
"the",
"accessTokens"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/db.go#L107-L109 |
13,881 | itsyouonline/identityserver | oauthservice/db.go | getAuthorizationRequest | func (m *Manager) getAuthorizationRequest(authorizationcode string) (ar *authorizationRequest, err error) {
ar = &authorizationRequest{}
err = m.getAuthorizationRequestCollection().Find(bson.M{"authorizationcode": authorizationcode}).One(ar)
if err != nil && err == mgo.ErrNotFound {
ar = nil
err = nil
return
}
return
} | go | func (m *Manager) getAuthorizationRequest(authorizationcode string) (ar *authorizationRequest, err error) {
ar = &authorizationRequest{}
err = m.getAuthorizationRequestCollection().Find(bson.M{"authorizationcode": authorizationcode}).One(ar)
if err != nil && err == mgo.ErrNotFound {
ar = nil
err = nil
return
}
return
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"getAuthorizationRequest",
"(",
"authorizationcode",
"string",
")",
"(",
"ar",
"*",
"authorizationRequest",
",",
"err",
"error",
")",
"{",
"ar",
"=",
"&",
"authorizationRequest",
"{",
"}",
"\n\n",
"err",
"=",
"m",
".",
"getAuthorizationRequestCollection",
"(",
")",
".",
"Find",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"authorizationcode",
"}",
")",
".",
"One",
"(",
"ar",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"err",
"==",
"mgo",
".",
"ErrNotFound",
"{",
"ar",
"=",
"nil",
"\n",
"err",
"=",
"nil",
"\n",
"return",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Get an authorizationRequest by it's authorizationcode. | [
"Get",
"an",
"authorizationRequest",
"by",
"it",
"s",
"authorizationcode",
"."
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/db.go#L112-L122 |
13,882 | itsyouonline/identityserver | oauthservice/db.go | saveAuthorizationRequest | func (m *Manager) saveAuthorizationRequest(ar *authorizationRequest) (err error) {
// TODO: Validation!
err = m.getAuthorizationRequestCollection().Insert(ar)
return
} | go | func (m *Manager) saveAuthorizationRequest(ar *authorizationRequest) (err error) {
// TODO: Validation!
err = m.getAuthorizationRequestCollection().Insert(ar)
return
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"saveAuthorizationRequest",
"(",
"ar",
"*",
"authorizationRequest",
")",
"(",
"err",
"error",
")",
"{",
"// TODO: Validation!",
"err",
"=",
"m",
".",
"getAuthorizationRequestCollection",
"(",
")",
".",
"Insert",
"(",
"ar",
")",
"\n\n",
"return",
"\n",
"}"
] | // saveAuthorizationRequest stores an authorizationRequest, only adding new authorizationRequests is allowed, updating is not | [
"saveAuthorizationRequest",
"stores",
"an",
"authorizationRequest",
"only",
"adding",
"new",
"authorizationRequests",
"is",
"allowed",
"updating",
"is",
"not"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/db.go#L125-L131 |
13,883 | itsyouonline/identityserver | oauthservice/db.go | saveAccessToken | func (m *Manager) saveAccessToken(at *AccessToken) (err error) {
// TODO: Validation!
err = m.getAccessTokenCollection().Insert(at)
return
} | go | func (m *Manager) saveAccessToken(at *AccessToken) (err error) {
// TODO: Validation!
err = m.getAccessTokenCollection().Insert(at)
return
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"saveAccessToken",
"(",
"at",
"*",
"AccessToken",
")",
"(",
"err",
"error",
")",
"{",
"// TODO: Validation!",
"err",
"=",
"m",
".",
"getAccessTokenCollection",
"(",
")",
".",
"Insert",
"(",
"at",
")",
"\n\n",
"return",
"\n",
"}"
] | // saveAccessToken stores an accessToken, only adding new accessTokens is allowed, updating is not | [
"saveAccessToken",
"stores",
"an",
"accessToken",
"only",
"adding",
"new",
"accessTokens",
"is",
"allowed",
"updating",
"is",
"not"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/db.go#L134-L140 |
13,884 | itsyouonline/identityserver | oauthservice/db.go | GetAccessToken | func (m *Manager) GetAccessToken(token string) (at *AccessToken, err error) {
at = &AccessToken{}
err = m.getAccessTokenCollection().Find(bson.M{"accesstoken": token}).One(at)
if err != nil && err == mgo.ErrNotFound {
at = nil
err = nil
return
}
if err != nil {
at = nil
return
}
if at.IsExpired() {
at = nil
err = nil
}
return
} | go | func (m *Manager) GetAccessToken(token string) (at *AccessToken, err error) {
at = &AccessToken{}
err = m.getAccessTokenCollection().Find(bson.M{"accesstoken": token}).One(at)
if err != nil && err == mgo.ErrNotFound {
at = nil
err = nil
return
}
if err != nil {
at = nil
return
}
if at.IsExpired() {
at = nil
err = nil
}
return
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"GetAccessToken",
"(",
"token",
"string",
")",
"(",
"at",
"*",
"AccessToken",
",",
"err",
"error",
")",
"{",
"at",
"=",
"&",
"AccessToken",
"{",
"}",
"\n\n",
"err",
"=",
"m",
".",
"getAccessTokenCollection",
"(",
")",
".",
"Find",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"token",
"}",
")",
".",
"One",
"(",
"at",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"err",
"==",
"mgo",
".",
"ErrNotFound",
"{",
"at",
"=",
"nil",
"\n",
"err",
"=",
"nil",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"at",
"=",
"nil",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"at",
".",
"IsExpired",
"(",
")",
"{",
"at",
"=",
"nil",
"\n",
"err",
"=",
"nil",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | //GetAccessToken gets an access token by it's actual token string
// If the token is not found or is expired, nil is returned | [
"GetAccessToken",
"gets",
"an",
"access",
"token",
"by",
"it",
"s",
"actual",
"token",
"string",
"If",
"the",
"token",
"is",
"not",
"found",
"or",
"is",
"expired",
"nil",
"is",
"returned"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/db.go#L144-L163 |
13,885 | itsyouonline/identityserver | oauthservice/db.go | getRefreshToken | func (m *Manager) getRefreshToken(token string) (rt *refreshToken, err error) {
rt = &refreshToken{}
err = m.getRefreshTokenCollection().Find(bson.M{"refreshtoken": token}).One(rt)
if err == mgo.ErrNotFound {
rt = nil
err = nil
}
if err != nil {
rt = nil
}
return
} | go | func (m *Manager) getRefreshToken(token string) (rt *refreshToken, err error) {
rt = &refreshToken{}
err = m.getRefreshTokenCollection().Find(bson.M{"refreshtoken": token}).One(rt)
if err == mgo.ErrNotFound {
rt = nil
err = nil
}
if err != nil {
rt = nil
}
return
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"getRefreshToken",
"(",
"token",
"string",
")",
"(",
"rt",
"*",
"refreshToken",
",",
"err",
"error",
")",
"{",
"rt",
"=",
"&",
"refreshToken",
"{",
"}",
"\n\n",
"err",
"=",
"m",
".",
"getRefreshTokenCollection",
"(",
")",
".",
"Find",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"token",
"}",
")",
".",
"One",
"(",
"rt",
")",
"\n",
"if",
"err",
"==",
"mgo",
".",
"ErrNotFound",
"{",
"rt",
"=",
"nil",
"\n",
"err",
"=",
"nil",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"rt",
"=",
"nil",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | //getRefreshToken gets an refresh token by it's refresh token string
// If the token is not found or is expired, nil is returned | [
"getRefreshToken",
"gets",
"an",
"refresh",
"token",
"by",
"it",
"s",
"refresh",
"token",
"string",
"If",
"the",
"token",
"is",
"not",
"found",
"or",
"is",
"expired",
"nil",
"is",
"returned"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/db.go#L204-L217 |
13,886 | itsyouonline/identityserver | oauthservice/db.go | saveRefreshToken | func (m *Manager) saveRefreshToken(t *refreshToken) (err error) {
if t == nil {
return
}
_, err = m.getRefreshTokenCollection().Upsert(bson.M{"refreshtoken": t.RefreshToken}, t)
return
} | go | func (m *Manager) saveRefreshToken(t *refreshToken) (err error) {
if t == nil {
return
}
_, err = m.getRefreshTokenCollection().Upsert(bson.M{"refreshtoken": t.RefreshToken}, t)
return
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"saveRefreshToken",
"(",
"t",
"*",
"refreshToken",
")",
"(",
"err",
"error",
")",
"{",
"if",
"t",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"m",
".",
"getRefreshTokenCollection",
"(",
")",
".",
"Upsert",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"t",
".",
"RefreshToken",
"}",
",",
"t",
")",
"\n\n",
"return",
"\n",
"}"
] | // saveRefreshToken stores a refreshToken | [
"saveRefreshToken",
"stores",
"a",
"refreshToken"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/db.go#L220-L228 |
13,887 | itsyouonline/identityserver | oauthservice/db.go | getClientsCollection | func (m *Manager) getClientsCollection() *mgo.Collection {
return db.GetCollection(m.session, clientsCollectionName)
} | go | func (m *Manager) getClientsCollection() *mgo.Collection {
return db.GetCollection(m.session, clientsCollectionName)
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"getClientsCollection",
"(",
")",
"*",
"mgo",
".",
"Collection",
"{",
"return",
"db",
".",
"GetCollection",
"(",
"m",
".",
"session",
",",
"clientsCollectionName",
")",
"\n",
"}"
] | //getClientsCollection returns the mongo collection for the clients | [
"getClientsCollection",
"returns",
"the",
"mongo",
"collection",
"for",
"the",
"clients"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/db.go#L231-L233 |
13,888 | itsyouonline/identityserver | oauthservice/db.go | GetClientLabels | func (m *Manager) GetClientLabels(clientID string) (labels []string, err error) {
results := []struct{ Label string }{}
err = m.getClientsCollection().Find(bson.M{"clientid": clientID}).Select(bson.M{"label": 1}).All(&results)
labels = make([]string, len(results), len(results))
for i, value := range results {
labels[i] = value.Label
}
return
} | go | func (m *Manager) GetClientLabels(clientID string) (labels []string, err error) {
results := []struct{ Label string }{}
err = m.getClientsCollection().Find(bson.M{"clientid": clientID}).Select(bson.M{"label": 1}).All(&results)
labels = make([]string, len(results), len(results))
for i, value := range results {
labels[i] = value.Label
}
return
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"GetClientLabels",
"(",
"clientID",
"string",
")",
"(",
"labels",
"[",
"]",
"string",
",",
"err",
"error",
")",
"{",
"results",
":=",
"[",
"]",
"struct",
"{",
"Label",
"string",
"}",
"{",
"}",
"\n",
"err",
"=",
"m",
".",
"getClientsCollection",
"(",
")",
".",
"Find",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"clientID",
"}",
")",
".",
"Select",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"1",
"}",
")",
".",
"All",
"(",
"&",
"results",
")",
"\n",
"labels",
"=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"results",
")",
",",
"len",
"(",
"results",
")",
")",
"\n",
"for",
"i",
",",
"value",
":=",
"range",
"results",
"{",
"labels",
"[",
"i",
"]",
"=",
"value",
".",
"Label",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | //GetClientLabels returns a list of labels for which there are apikeys registered for a specific client | [
"GetClientLabels",
"returns",
"a",
"list",
"of",
"labels",
"for",
"which",
"there",
"are",
"apikeys",
"registered",
"for",
"a",
"specific",
"client"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/db.go#L236-L244 |
13,889 | itsyouonline/identityserver | oauthservice/db.go | CreateClient | func (m *Manager) CreateClient(client *Oauth2Client) (err error) {
err = m.getClientsCollection().Insert(client)
if err != nil && mgo.IsDup(err) {
err = db.ErrDuplicate
}
return
} | go | func (m *Manager) CreateClient(client *Oauth2Client) (err error) {
err = m.getClientsCollection().Insert(client)
if err != nil && mgo.IsDup(err) {
err = db.ErrDuplicate
}
return
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"CreateClient",
"(",
"client",
"*",
"Oauth2Client",
")",
"(",
"err",
"error",
")",
"{",
"err",
"=",
"m",
".",
"getClientsCollection",
"(",
")",
".",
"Insert",
"(",
"client",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"&&",
"mgo",
".",
"IsDup",
"(",
"err",
")",
"{",
"err",
"=",
"db",
".",
"ErrDuplicate",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | //CreateClient saves an Oauth2 client | [
"CreateClient",
"saves",
"an",
"Oauth2",
"client"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/db.go#L247-L255 |
13,890 | itsyouonline/identityserver | oauthservice/db.go | UpdateClient | func (m *Manager) UpdateClient(clientID, oldLabel, newLabel string, callbackURL string, clientcredentialsGrantType bool) (err error) {
_, err = m.getClientsCollection().UpdateAll(bson.M{"clientid": clientID, "label": oldLabel}, bson.M{"$set": bson.M{"label": newLabel, "callbackurl": callbackURL, "clientcredentialsgranttype": clientcredentialsGrantType}})
if err != nil && mgo.IsDup(err) {
err = db.ErrDuplicate
}
return
} | go | func (m *Manager) UpdateClient(clientID, oldLabel, newLabel string, callbackURL string, clientcredentialsGrantType bool) (err error) {
_, err = m.getClientsCollection().UpdateAll(bson.M{"clientid": clientID, "label": oldLabel}, bson.M{"$set": bson.M{"label": newLabel, "callbackurl": callbackURL, "clientcredentialsgranttype": clientcredentialsGrantType}})
if err != nil && mgo.IsDup(err) {
err = db.ErrDuplicate
}
return
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"UpdateClient",
"(",
"clientID",
",",
"oldLabel",
",",
"newLabel",
"string",
",",
"callbackURL",
"string",
",",
"clientcredentialsGrantType",
"bool",
")",
"(",
"err",
"error",
")",
"{",
"_",
",",
"err",
"=",
"m",
".",
"getClientsCollection",
"(",
")",
".",
"UpdateAll",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"clientID",
",",
"\"",
"\"",
":",
"oldLabel",
"}",
",",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"newLabel",
",",
"\"",
"\"",
":",
"callbackURL",
",",
"\"",
"\"",
":",
"clientcredentialsGrantType",
"}",
"}",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"&&",
"mgo",
".",
"IsDup",
"(",
"err",
")",
"{",
"err",
"=",
"db",
".",
"ErrDuplicate",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | //UpdateClient updates the label, callbackurl and clientCredentialsGrantType properties of a client | [
"UpdateClient",
"updates",
"the",
"label",
"callbackurl",
"and",
"clientCredentialsGrantType",
"properties",
"of",
"a",
"client"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/db.go#L258-L266 |
13,891 | itsyouonline/identityserver | oauthservice/db.go | DeleteClient | func (m *Manager) DeleteClient(clientID, label string) (err error) {
_, err = m.getClientsCollection().RemoveAll(bson.M{"clientid": clientID, "label": label})
return
} | go | func (m *Manager) DeleteClient(clientID, label string) (err error) {
_, err = m.getClientsCollection().RemoveAll(bson.M{"clientid": clientID, "label": label})
return
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"DeleteClient",
"(",
"clientID",
",",
"label",
"string",
")",
"(",
"err",
"error",
")",
"{",
"_",
",",
"err",
"=",
"m",
".",
"getClientsCollection",
"(",
")",
".",
"RemoveAll",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"clientID",
",",
"\"",
"\"",
":",
"label",
"}",
")",
"\n",
"return",
"\n",
"}"
] | //DeleteClient removes a client secret by it's clientID and label | [
"DeleteClient",
"removes",
"a",
"client",
"secret",
"by",
"it",
"s",
"clientID",
"and",
"label"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/db.go#L269-L272 |
13,892 | itsyouonline/identityserver | oauthservice/db.go | DeleteAllForOrganization | func (m *Manager) DeleteAllForOrganization(clientID string) (err error) {
_, err = m.getClientsCollection().RemoveAll(bson.M{"clientid": clientID})
return
} | go | func (m *Manager) DeleteAllForOrganization(clientID string) (err error) {
_, err = m.getClientsCollection().RemoveAll(bson.M{"clientid": clientID})
return
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"DeleteAllForOrganization",
"(",
"clientID",
"string",
")",
"(",
"err",
"error",
")",
"{",
"_",
",",
"err",
"=",
"m",
".",
"getClientsCollection",
"(",
")",
".",
"RemoveAll",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"clientID",
"}",
")",
"\n",
"return",
"\n",
"}"
] | //DeleteAllForOrganization removes al client secrets for the organization | [
"DeleteAllForOrganization",
"removes",
"al",
"client",
"secrets",
"for",
"the",
"organization"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/db.go#L275-L278 |
13,893 | itsyouonline/identityserver | oauthservice/db.go | GetClient | func (m *Manager) GetClient(clientID, label string) (client *Oauth2Client, err error) {
client = &Oauth2Client{}
err = m.getClientsCollection().Find(bson.M{"clientid": clientID, "label": label}).One(client)
if err == mgo.ErrNotFound {
err = nil
client = nil
return
}
return
} | go | func (m *Manager) GetClient(clientID, label string) (client *Oauth2Client, err error) {
client = &Oauth2Client{}
err = m.getClientsCollection().Find(bson.M{"clientid": clientID, "label": label}).One(client)
if err == mgo.ErrNotFound {
err = nil
client = nil
return
}
return
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"GetClient",
"(",
"clientID",
",",
"label",
"string",
")",
"(",
"client",
"*",
"Oauth2Client",
",",
"err",
"error",
")",
"{",
"client",
"=",
"&",
"Oauth2Client",
"{",
"}",
"\n",
"err",
"=",
"m",
".",
"getClientsCollection",
"(",
")",
".",
"Find",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"clientID",
",",
"\"",
"\"",
":",
"label",
"}",
")",
".",
"One",
"(",
"client",
")",
"\n",
"if",
"err",
"==",
"mgo",
".",
"ErrNotFound",
"{",
"err",
"=",
"nil",
"\n",
"client",
"=",
"nil",
"\n",
"return",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | //GetClient retrieves a client given a clientid and a label | [
"GetClient",
"retrieves",
"a",
"client",
"given",
"a",
"clientid",
"and",
"a",
"label"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/db.go#L281-L290 |
13,894 | itsyouonline/identityserver | oauthservice/db.go | AllByClientID | func (m *Manager) AllByClientID(clientID string) (clients []*Oauth2Client, err error) {
clients = make([]*Oauth2Client, 0)
err = m.getClientsCollection().Find(bson.M{"clientid": clientID}).All(&clients)
return
} | go | func (m *Manager) AllByClientID(clientID string) (clients []*Oauth2Client, err error) {
clients = make([]*Oauth2Client, 0)
err = m.getClientsCollection().Find(bson.M{"clientid": clientID}).All(&clients)
return
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"AllByClientID",
"(",
"clientID",
"string",
")",
"(",
"clients",
"[",
"]",
"*",
"Oauth2Client",
",",
"err",
"error",
")",
"{",
"clients",
"=",
"make",
"(",
"[",
"]",
"*",
"Oauth2Client",
",",
"0",
")",
"\n\n",
"err",
"=",
"m",
".",
"getClientsCollection",
"(",
")",
".",
"Find",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"clientID",
"}",
")",
".",
"All",
"(",
"&",
"clients",
")",
"\n",
"return",
"\n",
"}"
] | //AllByClientID retrieves all clients with a given ID | [
"AllByClientID",
"retrieves",
"all",
"clients",
"with",
"a",
"given",
"ID"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/db.go#L293-L298 |
13,895 | itsyouonline/identityserver | oauthservice/db.go | RemoveTokensByGlobalID | func (m *Manager) RemoveTokensByGlobalID(globalid string) error {
_, err := m.getAccessTokenCollection().RemoveAll(bson.M{"globalid": globalid})
return err
} | go | func (m *Manager) RemoveTokensByGlobalID(globalid string) error {
_, err := m.getAccessTokenCollection().RemoveAll(bson.M{"globalid": globalid})
return err
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"RemoveTokensByGlobalID",
"(",
"globalid",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"m",
".",
"getAccessTokenCollection",
"(",
")",
".",
"RemoveAll",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"globalid",
"}",
")",
"\n",
"return",
"err",
"\n",
"}"
] | //RemoveTokensByGlobalID removes oauth tokens by global id | [
"RemoveTokensByGlobalID",
"removes",
"oauth",
"tokens",
"by",
"global",
"id"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/db.go#L313-L316 |
13,896 | itsyouonline/identityserver | oauthservice/db.go | RemoveClientsByID | func (m *Manager) RemoveClientsByID(clientid string) error {
_, err := m.getAccessTokenCollection().RemoveAll(bson.M{"clientid": clientid})
return err
} | go | func (m *Manager) RemoveClientsByID(clientid string) error {
_, err := m.getAccessTokenCollection().RemoveAll(bson.M{"clientid": clientid})
return err
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"RemoveClientsByID",
"(",
"clientid",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"m",
".",
"getAccessTokenCollection",
"(",
")",
".",
"RemoveAll",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"clientid",
"}",
")",
"\n",
"return",
"err",
"\n",
"}"
] | //RemoveClientsByID removes oauth clients by client id | [
"RemoveClientsByID",
"removes",
"oauth",
"clients",
"by",
"client",
"id"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/db.go#L319-L322 |
13,897 | itsyouonline/identityserver | routes/routes.go | GetRouter | func GetRouter(sc *siteservice.Service, is *identityservice.Service, oauthsc *oauthservice.Service) http.Handler {
r := mux.NewRouter().StrictSlash(true)
sc.AddRoutes(r)
sc.InitModels()
apiRouter := r.PathPrefix("/api").Subrouter()
is.AddRoutes(apiRouter)
oauthsc.AddRoutes(r)
// Add middlewares
router := NewRouter(r)
dbmw := db.DBMiddleware()
recovery := handlers.RecoveryHandler()
router.Use(recovery, LoggingMiddleware, dbmw, sc.SetWebUserMiddleWare)
return router.Handler()
} | go | func GetRouter(sc *siteservice.Service, is *identityservice.Service, oauthsc *oauthservice.Service) http.Handler {
r := mux.NewRouter().StrictSlash(true)
sc.AddRoutes(r)
sc.InitModels()
apiRouter := r.PathPrefix("/api").Subrouter()
is.AddRoutes(apiRouter)
oauthsc.AddRoutes(r)
// Add middlewares
router := NewRouter(r)
dbmw := db.DBMiddleware()
recovery := handlers.RecoveryHandler()
router.Use(recovery, LoggingMiddleware, dbmw, sc.SetWebUserMiddleWare)
return router.Handler()
} | [
"func",
"GetRouter",
"(",
"sc",
"*",
"siteservice",
".",
"Service",
",",
"is",
"*",
"identityservice",
".",
"Service",
",",
"oauthsc",
"*",
"oauthservice",
".",
"Service",
")",
"http",
".",
"Handler",
"{",
"r",
":=",
"mux",
".",
"NewRouter",
"(",
")",
".",
"StrictSlash",
"(",
"true",
")",
"\n\n",
"sc",
".",
"AddRoutes",
"(",
"r",
")",
"\n",
"sc",
".",
"InitModels",
"(",
")",
"\n\n",
"apiRouter",
":=",
"r",
".",
"PathPrefix",
"(",
"\"",
"\"",
")",
".",
"Subrouter",
"(",
")",
"\n",
"is",
".",
"AddRoutes",
"(",
"apiRouter",
")",
"\n",
"oauthsc",
".",
"AddRoutes",
"(",
"r",
")",
"\n\n",
"// Add middlewares",
"router",
":=",
"NewRouter",
"(",
"r",
")",
"\n\n",
"dbmw",
":=",
"db",
".",
"DBMiddleware",
"(",
")",
"\n",
"recovery",
":=",
"handlers",
".",
"RecoveryHandler",
"(",
")",
"\n\n",
"router",
".",
"Use",
"(",
"recovery",
",",
"LoggingMiddleware",
",",
"dbmw",
",",
"sc",
".",
"SetWebUserMiddleWare",
")",
"\n\n",
"return",
"router",
".",
"Handler",
"(",
")",
"\n",
"}"
] | //GetRouter contructs the router hierarchy and registers all handlers and middleware | [
"GetRouter",
"contructs",
"the",
"router",
"hierarchy",
"and",
"registers",
"all",
"handlers",
"and",
"middleware"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/routes/routes.go#L16-L35 |
13,898 | itsyouonline/identityserver | credentials/totp/db.go | Validate | func (pwm *Manager) Validate(username, securityCode string) (bool, error) {
var storedSecret userSecret
if err := pwm.collection.Find(bson.M{"username": username}).One(&storedSecret); err != nil {
if err == mgo.ErrNotFound {
log.Debug("No totpsecret found for this user")
return false, nil
}
log.Debug(err)
return false, err
}
token := TokenFromSecret(storedSecret.Secret)
match := token.Validate(securityCode)
return match, nil
} | go | func (pwm *Manager) Validate(username, securityCode string) (bool, error) {
var storedSecret userSecret
if err := pwm.collection.Find(bson.M{"username": username}).One(&storedSecret); err != nil {
if err == mgo.ErrNotFound {
log.Debug("No totpsecret found for this user")
return false, nil
}
log.Debug(err)
return false, err
}
token := TokenFromSecret(storedSecret.Secret)
match := token.Validate(securityCode)
return match, nil
} | [
"func",
"(",
"pwm",
"*",
"Manager",
")",
"Validate",
"(",
"username",
",",
"securityCode",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"var",
"storedSecret",
"userSecret",
"\n",
"if",
"err",
":=",
"pwm",
".",
"collection",
".",
"Find",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"username",
"}",
")",
".",
"One",
"(",
"&",
"storedSecret",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"mgo",
".",
"ErrNotFound",
"{",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"log",
".",
"Debug",
"(",
"err",
")",
"\n",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"token",
":=",
"TokenFromSecret",
"(",
"storedSecret",
".",
"Secret",
")",
"\n",
"match",
":=",
"token",
".",
"Validate",
"(",
"securityCode",
")",
"\n",
"return",
"match",
",",
"nil",
"\n",
"}"
] | //Validate checks the totp code for a specific username | [
"Validate",
"checks",
"the",
"totp",
"code",
"for",
"a",
"specific",
"username"
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/credentials/totp/db.go#L53-L67 |
13,899 | itsyouonline/identityserver | credentials/totp/db.go | Save | func (pwm *Manager) Save(username, secret string) error {
//TODO: username and secret validation
storedSecret := userSecret{Username: username, Secret: secret}
_, err := pwm.collection.Upsert(bson.M{"username": username}, storedSecret)
return err
} | go | func (pwm *Manager) Save(username, secret string) error {
//TODO: username and secret validation
storedSecret := userSecret{Username: username, Secret: secret}
_, err := pwm.collection.Upsert(bson.M{"username": username}, storedSecret)
return err
} | [
"func",
"(",
"pwm",
"*",
"Manager",
")",
"Save",
"(",
"username",
",",
"secret",
"string",
")",
"error",
"{",
"//TODO: username and secret validation",
"storedSecret",
":=",
"userSecret",
"{",
"Username",
":",
"username",
",",
"Secret",
":",
"secret",
"}",
"\n\n",
"_",
",",
"err",
":=",
"pwm",
".",
"collection",
".",
"Upsert",
"(",
"bson",
".",
"M",
"{",
"\"",
"\"",
":",
"username",
"}",
",",
"storedSecret",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] | // Save stores a secret for a specific username. | [
"Save",
"stores",
"a",
"secret",
"for",
"a",
"specific",
"username",
"."
] | 333d78810c675fe259e970c190f35a5dc5586569 | https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/credentials/totp/db.go#L81-L89 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.