Add "resource" to LoginURL if defined. That helps to get 2FA

This commit is contained in:
Pavel Sorokin 2017-09-07 13:53:53 +08:00
parent 59adce3d63
commit 4f67c1acd4
2 changed files with 19 additions and 0 deletions

View File

@ -206,7 +206,11 @@ func (p *AzureProvider) GetLoginURL(redirectURI, state string) string {
params.Add("state", state)
params.Set("prompt", p.ApprovalPrompt)
params.Set("nonce", "FIXME")
if p.ProtectedResource != nil && p.ProtectedResource.String() != "" {
params.Add("resource", p.ProtectedResource.String())
}
a.RawQuery = params.Encode()
return a.String()
}

View File

@ -351,3 +351,18 @@ func TestAzureRightPermittedGroups(t *testing.T) {
assert.Equal(t, true, result)
}
func TestAzureLoginURLnoResource(t *testing.T) {
p := testAzureProvider("")
p.ProtectedResource = nil
result := p.GetLoginURL("http://redirect/url", "state")
assert.Equal(t, "?client_id=&nonce=FIXME&prompt=&redirect_uri=http%3A%2F%2Fredirect%2Furl&response_mode=form_post&response_type=id_token+code&scope=openid&state=state", result)
}
func TestAzureLoginURL(t *testing.T) {
p := testAzureProvider("")
result := p.GetLoginURL("http://redirect/url", "state")
assert.Equal(t, "?client_id=&nonce=FIXME&prompt=&redirect_uri=http%3A%2F%2Fredirect%2Furl&resource=https%3A%2F%2Fgraph.microsoft.com&response_mode=form_post&response_type=id_token+code&scope=openid&state=state", result)
}