Skip to content

Commit ba93030

Browse files
ChrSteinertKrzysztof-Cieslak
authored andcommitted
Adjusts xml docs and adds custom AzureAD OAuth operation.
1 parent 4f8910c commit ba93030

File tree

1 file changed

+22
-1
lines changed
  • src/Saturn.Extensions.Authorization

1 file changed

+22
-1
lines changed

src/Saturn.Extensions.Authorization/OAuth.fs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ type Saturn.Application.ApplicationBuilder with
128128
CookiesAlreadyAdded = true
129129
}
130130

131-
///Enalbes Azure Active Directory authentication.
131+
///Enalbes default Azure AD OAuth authentication.
132132
///`scopes` must be at least on of the scopes defined in https://docs.microsoft.com/en-us/graph/permissions-reference, for instance "User.Read".
133133
///`jsonToClaimMap` should contain sequance of tuples where first element is a name of the of the key in JSON object and second element is a name of the claim.
134134
///For example: `["name", "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name" ]` where `name` is the names of a field in Azure AD's JSON response (see https://docs.microsoft.com/en-us/azure/active-directory/develop/id-tokens or inspect tokens with https://jwt.ms).
@@ -164,3 +164,24 @@ type Saturn.Application.ApplicationBuilder with
164164
AppConfigs = middleware::state.AppConfigs
165165
CookiesAlreadyAdded = true
166166
}
167+
168+
///Enables AzureAD OAuth authentication with custom configuration
169+
[<CustomOperation("use_azuread_oauth_with_config")>]
170+
member __.UseAzureADAuthWithConfig(state: ApplicationState, (config : Authentication.OAuth.OAuthOptions -> unit) ) =
171+
let middleware (app : IApplicationBuilder) =
172+
app.UseAuthentication()
173+
174+
let service (s : IServiceCollection) =
175+
let c = s.AddAuthentication(fun cfg ->
176+
cfg.DefaultScheme <- CookieAuthenticationDefaults.AuthenticationScheme
177+
cfg.DefaultSignInScheme <- CookieAuthenticationDefaults.AuthenticationScheme
178+
cfg.DefaultChallengeScheme <- "AzureAD")
179+
addCookie state c
180+
c.AddOAuth("AzureAD",config) |> ignore
181+
s
182+
183+
{ state with
184+
ServicesConfig = service::state.ServicesConfig
185+
AppConfigs = middleware::state.AppConfigs
186+
CookiesAlreadyAdded = true
187+
}

0 commit comments

Comments
 (0)