Skip to content

Commit d52b612

Browse files
committed
add usage section in readme
1 parent 2a1e7b5 commit d52b612

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,47 @@ If bundler is not being used to manage dependencies, install the gem by executin
2323

2424
## Usage
2525

26+
You can use predefined Providers to load an identity from for example Discord:
27+
```ruby
2628

29+
begin
30+
31+
identity = Code0::Identities::Provider::Discord.new(
32+
-> {
33+
redirect_uri : "http://localhost:8080/redirect",
34+
client_id : "id"
35+
client_secret : "xxxx"
36+
}).load_identity({ code: "a_valid_code" })
37+
38+
rescue Code0::Error => e
39+
puts "Error occurred while loading the identity", e
40+
exit!
41+
end
42+
43+
# Then you can use the details from the user
44+
puts identity.provider # = :discord
45+
puts identity.username
46+
puts identity.identifier
47+
# ...
48+
49+
```
50+
51+
Or you can use a provider with multiple configured providers:
52+
53+
```ruby
54+
55+
identity_provider = Code0::Identities::IdentityProvider.new
56+
57+
identity_provider.add_provider(:gitlab, my_gitlab_configuration)
58+
identity_provider.add_named_provider(:my_custom_gitlab_provider, :gitlab, my_custom_gitlab_provider_configuration)
59+
60+
# Now you can either use the custom "my_custom_gitlab_provider" provider
61+
# or the "gitlab" provider
62+
63+
identity_provider.load_identity(:gitlab, params)
64+
65+
# or
66+
67+
identity_provider.load_identity(:my_custom_gitlab_provider, params)
68+
69+
```

0 commit comments

Comments
 (0)